Why Wasm is the future of cloud computing

Whether on the server or on the edge, Wasm lets you create custom logic that runs much closer to the data than it could before. And you can do it securely, efficiently, and with greater flexibility.

Cloud future

Wasm may just be the most important emerging technology that you’ve never heard of. Ok, maybe you’ve heard of it. It’s important!

Shorthand for WebAssembly language, Wasm was developed for the web. However, Wasm technology has expanded beyond the web browser. Now organizations are starting to run Wasm on the server side. For example, my company, SingleStore, is using it in our database.

Some think Wasm will replace container technology and the ubiquitous JavaScript.

Whether or not you believe that, Wasm is clearly making an impact on cloud computing. Why and how? Let’s count the ways.

Wasm is cross-platform: Making it safer and simpler to bring cloud components together

People use all different kinds of languages to write software. Getting those languages to interact with each other is difficult. Wasm provides a framework in which you can write in whatever language you want. Then it produces a common, simulated machine format.

That format allows components written in various languages—like Rust, C/C++, and Go—to talk to each other. Wasm also provides the ability for server-side systems like databases to embed components from different languages without requiring you to know or care how that module was produced.

Think of Wasm as a universal plugin format. Say you would like to augment your system’s capabilities with a component developed by a third party. Wasm lets you bring the new component into your system without the risks that typically come with integrating add-ons. For example, an external component might crash the system or work in an unexpected way. Wasm mitigates these problems by creating an extremely safe framework for disparate systems and components to interact together.

The cloud is a big driver of Wasm’s expansion. Wasm is a good match for cloud because it’s virtualized and can work in any environment that supports the Wasm runtime. Also, cloud systems are typically composed of many services pieced together and connected in different ways. That can get complicated. But the more you can simplify your cloud environment, the easier it is for various aspects of cloud systems to work together correctly.

Wasm is secure: Lowering risk with its approach to running code and representing functions

In most language runtimes, functions have addresses. Those addresses are executable points in memory. If you are just looking at memory as a bunch of bytes, a function may be indistinguishable from the rest of the memory. This opens the door for people to find the function and inject code into it, or call a function in a privileged way so the function does something that it’s not supposed to do. Wasm’s design eliminates those problems.

Wasm represents functions in a way that is not exploitable. It also runs the code in a sandbox, which mitigates common security problems associated with running untrusted code. Because Wasm encapsulates the program memory in a safe area, nothing can get outside of it and access other places that might affect the host that’s running the program or compromise security.

And with Wasm’s capability-based security model, hosts have complete control over what kinds of privileged operations the Wasm program can run. For example, hosts must explicitly grant access to directories if file access is a requirement.

Wasm is fast: Eliminating what is not needed and enabling greater speed and efficiency

Clearly, Wasm isn’t the first technology people have used to bring things together in a safer, more simplified way. However, Wasm is much faster than some of those other technologies.

Compilers can generate Wasm programs by leveraging the LLVM back end, compiling down to the LLVM intermediate representation. LLVM, or low level virtual machine, is an extracted machine that many languages already compile down to. As a result of this approach, and thanks to many years of community effort around the LLVM project, Wasm programs can be compiled to highly optimized machine code.

At SingleStore, we created the Wasm Space Program—a virtual real-time universe inside a database—to demonstrate how fast and lightweight Wasm is. In this simulation, spaceships use different strategies to replenish energy and fight other spacecraft in a vast, real-time “universe.” That involves a vast amount of data, with more than one million ships in the system and nearly three million database updates per second.

Traditionally, integrating that data and assembling it on a mid-tier layer would require you to pull up a lot of data to the mid-tier. That could introduce a huge amount of lag, and require some complex caching to achieve a real-time response. Rather than taking that approach, each spaceship’s strategy has been written in Wasm, and loaded into the database as a UDF. Each second, each of the spaceships’ strategy functions are invoked to decide on its next move.

There’s nothing on the front end—a JavaScript program running in the browser—that understands these strategies, or anything about the state of the universe. Its job is simply to issue SQL queries directly to the database and graphically present the information that is returned. The database maintains all of the state  information, and because Wasm has allowed the compute to be right next to the data, it’s a lot faster. No mid-tier was even necessary.

But Wasm isn’t all fun and games. You can use it to address countless other applications and use cases. For example, you could use Wasm for sentiment analysis. The kind of complex logic required for sentiment analysis isn’t something that can easily be expressed in a database SQL dialect. So, in order to do this, you usually need to implement it in a more sophisticated language and then bring the data to it by downloading each row of data. Then you need to push the sentiment analysis rating back into the database. That means a round trip for every row in the database you use. If you have millions of rows, that creates a lot of network traffic. But with the way SingleStore has integrated Wasm, you are already in the database, so you don’t incur that overhead.

Wasm is getting better all the time: Creating standards makes it even more powerful

Wasm is already very capable. And with the new technologies and standards that are on the way, Wasm will let you do even more.

For example, the W3C WebAssembly Community Group, with help from members of organizations such as the Bytecode Alliance (of which SingleStore is a member), is currently working on standardizing the WebAssembly System Interface (WASI). WASI will provide a standard set of APIs and services that can be used when Wasm modules are running on the server. Many standard proposals are still in progress, such as garbage collection, network I/O, and threading, so you can’t always map the things that you’re doing in other programming languages to Wasm. But eventually, WASI aims to provide a full standard that will help to achieve that. In many ways, the goals of WASI are similar to POSIX.

Wasm as it now stands also doesn’t address the ability to link or communicate with other Wasm modules. But the Wasm community, with support from members of the computing industry, is working on the creation of something called the component model. This aims to create a dynamic linking infrastructure around Wasm modules, defining how components start up and communicate with each other (similar to a traditional OS’s process model).

Additionally, an emerging standard IDL syntax, called WIT (for WebAssembly Interface Types), will allow people to describe their Wasm interfaces in a language-agnostic way. As a result, binding generators will be able to take what’s in the IDL and compile code that will allow both the Wasm host and the guest to communicate data back and forth in a common way.

Wasm is the future: Providing a faster, more secure, and more efficient way to bring things together

Wasm, though more lightweight, may not replace containers any time soon. But you can expect Wasm to become part of a whole lot of software going forward.

Whether on the server or on the edge, Wasm lets you create custom logic that runs much closer to the data than it could before—and you can do it securely, efficiently, and with greater flexibility.

And now with SingleStore, you can compile your existing programs to Wasm, push them into the database, and run them there. That means that you may not  have to rewrite that code and put it somewhere the data is not. With Wasm technology, you can have the best of both worlds. 

Peter Vetere has been developing software for 25 years. He currently works for SingleStoremaker of SingleStoreDB, a real-time distributed SQL database designed for data-intensive applications—as a member of the LaunchPad team, where he researches ways to bring innovative new ideas to the database.

New Tech Forum provides a venue to explore and discuss emerging enterprise technology in unprecedented depth and breadth. The selection is subjective, based on our pick of the technologies we believe to be important and of greatest interest to InfoWorld readers. InfoWorld does not accept marketing collateral for publication and reserves the right to edit all contributed content. Send all inquiries to newtechforum@infoworld.com.

Copyright © 2022 IDG Communications, Inc.