What is WebAssembly?
WebAssembly, or WASM for short, literally consists of Web and Assembly, which can be understood as web/browser assembly, indicating the origin of the technology, which is assembly code that runs inside a browser. However, as the technology has iterated, WebAssembly has long since moved beyond its original design vision.
- WebAssembly is not exactly assembly language, but rather an assembly bytecode-like instruction format standard maintained by the W3C’s WASM Working Group and the ByteCode Alliance. It is more like LLVM-IR, an intermediate language that is somewhat higher in abstraction than assembly language, and instead of writing WASM manually, developers choose to write and compile to WASM using other high-level languages (e.g. C, C++, Rust, Go, Python, etc.).
- WebAssembly is no longer limited to running on top of the browser. As the WASM ecosystem continues to expand, various WASM-compatible runtimes have emerged that allow WASM to run in a sandbox environment outside of the browser, on both the client and server sides.
Why do we need WebAssembly?
Features of WebAssembly
WASM has several key design features that make it an aura of its own from birth.
- Portability - As mentioned earlier, WASM was originally designed for the Web, and almost all major browsers now offer support for WASM; in addition, WASM was also designed for low-level virtual machine architectures, and its instructions are translated into machine code by the physical machine alone, which means that WASM binaries can eventually run on various combinations of operating systems and chip architectures, whether Linux, MacOS, Windows, and other operating systems, or in ARM, X86, Power, and other chip architectures, and even mobile devices and Internet of Things (IoT) devices.
- Security - WASM runs in a sandbox environment that values capability-driven security where access to host system resources (e.g. file systems, hardware, etc.) is restricted unless explicit capability access is granted, so WASM reduces the attack surface and enables secure restricted execution of untrusted code in a multi-tenant environment. This security model allows developers to extend existing applications with plugins and user submitted code.
- Multi-language support - WASM is a compiled target format that is programming language agnostic, and developers have the flexibility to build WASM in multiple languages (e.g. C, C++, Rust, Go, etc.) as long as the language supports it.Currently, almost all of the top 20 programming languages in RedMonk are adding WASM support.
WebAssembly usage scenarios
Application migration to the browser side
Serverless - Service-less platforms rely heavily on optimized cold start technologies, so the lightweight and efficient nature of WASM makes the WASM runtime, such as WASMEdge, ideally suited to power the next generation of serverless platforms, which continues to penetrate the edge computing space.
Data Analytics and Machine Learning at the Edge - WASM portability and efficiency features make it suitable for applications that support machine learning scenarios at the edge. WASM machine learning modules can be deployed on edge devices with widely varying form factors and computing power, with data computed close to the source of data generation, whether running at the edge of the network or at the edge of the device.
Service Mesh - Leveraging the flexibility of WASM allows the ability to scale a service mesh (such as Istio) down from the control plane to the data plane (such as extending Envoy with WASM), where the WASM extension itself runs in a sandbox environment and does not affect the operation of data plane programs and resource access is restricted.
Platform Extensions - Thanks to WASM’s multilingual support and sandbox isolation technology, WASM can provide a scalable model and the ability to execute third-party (trusted or untrusted) code on top of existing applications.
WASM Ecosystem Landscape.
The convergence of WebAssembly and container technology
It is believed that as the technology iterates, the WASM runtime will become a “first-class citizen” in the cloud-native space, as the WASI continues to improve and the OCI Registry supports the WASM program module, WASM may take application management to a new level. Just like the spread from virtual machine technology to containers, WASM may replace some of the functionality of container technology. With WASM’s cold-start optimization, WASM containers will be well suited for short-lived serverless and edge workloads; however, traditional container workloads will be dedicated to long-running services (such as caching servers) that require a lot of I/O or need access to network sockets.
Further, it is too early to tell how a mainstream container orchestration engine like Kubernetes will integrate with WASM, but we have seen the emergence of projects such as Krustlet, runwasi, Containerd WASM Shims, and crun’s WASM Handler, all of which aim to elevate WASM to first-class citizenship in container environments as the new runtime for Kubernetes.