WebAssembly (Wasm), originally developed by Mozilla, Google, Microsoft, Apple, and others at W3C, is a secure, cross-platform, and high-performance application runtime. It serves as the execution engine for compiled C/C++ applications in modern browsers.
Before Wasm, Linux containers are commonly used to run these compiled applications in the cloud — eg a Rust or C++ app is compiled to x86_64 machine code and runs inside a Linux container. Wasm provides a more secure, much lighter, faster, and more portable alternative to Linux containers for this type of performance-minded server-side application.
Compared with the traditional Linux containers, Wasm runtimes are safer since they have much-reduced attack surfaces (no OS libraries) and much simpler software supply chains. Wasm applications are portable across OSes and CPUs. They can be AOT compiled to native machine code at deployment time achieving near-native performance. Furthermore, Wasm consumes much less memory and resources than Linux containers.
Wasm as containers
The demo-microservices example is a fully featured microservice written in Rust. It provides a built-in HTTP server and a MySQL database client. It is compiled into Wasm and then deployed by Docker Compose in a WasmEdge container. In Docker Desktop, we see the size of the demo-microservices Wasm container image is only 3.05 MB, which is a fraction of traditional Linux images.
Wasm, and WasmEdge in particular, are supported by many mainstream container tools.
- crun and youki are OCI runtimes that support Wasm containers.
- containerd and CRI-O are CRI runtimes that support Wasm containers.
- Docker and Podman are user-facing management tools that support Wasm containers.
- Kubernetes, including kind, k3s, microk8s, OpenShift, and others, support orchestrating Wasm containers side by side with Linux containers.
Use cases for server-side WebAssembly
Cloud-native platforms need to support untrusted and high-performance applications. Wasm containers are great choices for these use cases.
As microservices grow popular, the infrastructure costs associated with their management are exploding. That is especially problematic for a new generation of microservice applications that are computationally intensive (i.e., AI) and performance critical (i.e., edge cloud applications).
Serverless functions are publicly accessible microservices. They are the fastest-growing product sector in public clouds.
Wasm is a secure sandbox for compiled applications. It is lightweight and portable, runs applications at near-native performance, and works seamlessly with container ecosystem tools like K8s and Docker. Developers can use the same workflow to build, deploy, and manage Wasm Apps. Wasm is a great choice for the next-generation edge cloud-based microservices. See how to create database backed microservices in Rust and WasmEdge.
As SaaS proliferates, the demands to automate, customize, or integrate SaaS products are also increasing. Traditional webhook-based SaaS APIs are slow, bloated, complex, and not secure enough for many automation use cases.
An emerging approach is for users to simply upload customization code onto the SaaS platform, which can be triggered by SaaS events. Examples include AWS Lambda, which allows you to customize AWS workflows through functions, and GitHub Actions, which allows users to automatically respond to events in GitHub using apps running on GitHub infra.
Wasm runtimes can be easily integrated into SaaS or database platforms. They are secure, portable, and lightweight. Once integrated, Wasm runtimes can run functions (or guest apps) written in a variety of different programming languages, supporting SaaS SDKs in all popular languages.
Modern data-intensive applications often need to filter, map, and transform data in streaming or messaging pipelines. That requires user-defined functions to be embedded into the data streaming platform.
For the same reason why Wasm is a great runtime for SaaS UDFs, it is a great choice for data streaming functions too. Furthermore, Wasm runtimes such as WasmEdge, provide high-performance APIs for AI/ML processing, which makes them ideal for running compute-intensive AI/ML workloads in many streaming analytics use cases.
Large public blockchain networks, such as Ethereum, EOS, Polkadot, NEAR, FileCoin, Cosmos, Ripple, have all committed to Wasm as their smart contract execution engines. In our view, smart contracts on public blockchain networks are decentralized serverless functions. Blockchains are ideal use cases for Wasm.
Show me the code
WasmEdge is a WebAssembly runtime that is specifically optimized for server-side and cloud-native applications. It is an open-source project managed by the Linux Foundation / CNCF. Its key features include the following.
- Seamlessly integrates into the existing cloud-native infra (e.g., Docker and K8s). Check out the Kubernetes guide.
- Fully supports the WASI specification for accessing operating system resources.
- Features a high-performance Ahead-of-Time (AOT) compiler, which drastically improves server-side application performance. It is the fastest WebAssembly on the market today.
- Supports non-block networking sockets and web services.
- Supports clients for databases, caches, and DOs.
- Supports AI inference frameworks and runtimes, such as Tensorflow, OpenVino, PyTorch, etc.
To see some code examples, check out the following tutorials. You could also refer to WasmEdge book.
The road ahead
The road ahead for server-side Wasm is very promising. WasmEdge has brought the cloud-native toolchain to WebAssembly, enabling developers to use their familiar workflow in Wasm application development. Companies such as Second State, Fermyon, Cosmonic, Suborbital, VMWare, Cloudflare, Fastly, SingleStore, Shopify, InfinyOn and Microsoft, have also launched/pre-launched their own WebAssembly-based public cloud services.
The Wasm community will continue to innovate in areas such as developer tooling and component model support. We expect more exciting news, tools, use cases, and partnerships to emerge in server-side Wasm.