When technology grows beyond intentions: WebAssembly for Serverless

WebAssembly for Serverless

November 12, 2024                                                  ⏱️ 6 min
By Andrei N. (RnD: WebFrontend Group)

Throughout history, technologies were mainly created to solve or address specific problems. But there were lots of cases when people realized afterwards that tools & technologies could have a broader application than was initially planned.

Same as web, which was created just for exchanging physics papers and became what it is, or JavaScript, which was initially a “kids’ language” to add interactivity on web pages and alerts in the browser, and became the world’s most popular language, WebAssembly has its moment now and it is growing beyond the intentions of its creators.

WebAssembly (shortened to WASM) was built for the web browser, and we have explained in this article why it is a game change for the web. But there are lot of other places where WASM is very promising and one of them is in the Cloud. WebAssembly is now regarded as a certainty in cloud technology and appears to be an excellent platform for running serverless functions.

A bit of history

Before we begin, it is important to point out what made WebAssembly different than the other attempts to bring in the browser code written in other languages than the traditional ones. If we look back in time, there were several attempts of this kind:

  • Java Applets (deprecated in 2007)
  • VBScript (some ephemeral attempt of Microsoft – it only worked on its browsers)
  • Adobe Flash & Microsoft’s Silverlight (they came and went)

So, what made WebAssembly so special to conquer so fast all the modern browsers and go even beyond that?

First of all is the way Mozilla (the initiators of WebAssembly) designed it. They joined forces with Google, Microsoft, Apple and others and they committed to do everything under the umbrella of the W3C standards.

Secondly is the nature of WebAssembly and its approach. Instead of supporting a language, they defined a binary format that existing languages could compile to. This is the key difference basically.

This is a print screen of this X (ex Twitter) post.

Although the above post originates in 2019, and it referred to the past, the next years confirmed how valid and visionary it was. As we speak, WebAssembly is a certitude outside the web and one of the domains where it seems like an excellent fit is Serverless Architectures.

This is what we are going to explore in the next paragraphs.

Why

Why did WebAssembly gain attention in cloud computing, especially in serverless environments? Well, it is mostly because of its lightweight, fast, and secure execution model.

Serverless functions (or Function-as-a-Service, FaaS) allow developers to execute small units of code in response to events without managing the underlying infrastructure. These functions need to be:

  • Lightweight: Quick to start up and execute, as they’re usually designed for brief, event-driven tasks.
  • Isolated and Secure: Since functions from different users may run on the same underlying hardware, security isolation is crucial.
  • Cross-Platform: Ideally, functions should work across different cloud environments with minimal adjustments.

In this regard, WASM aligns with all the needs, and these are the reasons it is a great fit:

  • Low Overhead: WASM modules are small and optimized for rapid start times, reducing “cold start” latency, a common challenge in serverless architectures.
  • Security and Isolation: WASM was designed with a strong sandboxing model, which isolates modules and restricts their access to the underlying system—enhancing security in multi-tenant environments.
  • Cross-Platform Compatibility: WASM runs the same code across different systems, regardless of OS or hardware, making it a highly portable option for serverless workloads across cloud providers.

With its sandboxing, low latency, and cross-platform support, WebAssembly can efficiently handle short-lived, event-driven tasks typical of serverless applications. This makes it a viable option as more cloud providers started to integrate WASM into their serverless offerings.

How

While WASM itself is powerful, it was originally built just for the web, so it lacked features required for typical non-web applications (like file access, network access, system calls, etc.). All these gaps were addressed by WASI (WebAssembly System Interface).

WASI is a standardized API that allows WebAssembly modules to interact with the host environment’s system resources, like file systems, networking, and clocks, in a controlled and platform-independent way. WASI was developed by the Bytecode Alliance, an open-source organization created by Mozilla, Fastly, Intel and others to promote secure, fast, and portable WebAssembly-based software.

Thus, WASI provides a standardized way for WebAssembly modules to interact with the host system, bringing WASM closer to the functionality of traditional binaries while maintaining its portability and security.

Here are the key Features of WASI:

  • Platform Independence: WASI is designed to be cross-platform, allowing WASM applications to run in various environments without modification.
  • Security by Default: It extends WASM’s sandboxing model, ensuring that WASM modules only access system resources explicitly allowed by the runtime.
  • Modular API: WASI provides basic capabilities, such as file I/O, networking, and clock access, in a modular way. This modular design allows applications to use only the capabilities they need, preserving security and performance.

Tooling

Programming languages and technologies are not enough to build apps or functions used in real life scenarios. Frameworks are crucial for development as they fill in the gaps by providing essential tools, abstractions and integrations that make it easier to develop, deploy, and manage apps. The same applies when it comes to using WASM to develop serverless functions effectively. There are already a couple of frameworks available on the market in this regard and we are going to explore two of them:

These two seem to be the top viable options nowadays for developing WASM based serverless functions.
Both are specifically designed to leverage WASM’s strengths in serverless environments and provide the tools, scalability, and security necessary to run event-driven, cloud-native applications efficiently.

Fermyon Spin

Fermyon Spin is widely known as a top framework for creating and deploying WASM based serverless applications.

The strengths of Spin are the following:

  • Ease of Use: Spin’s developer tools and CLI make it easy to build serverless functions without extensive setup or infrastructure management.
  • High Performance for Stateless Functions: Fermyon Spin is well suited for stateless serverless functions that benefit from WASM’s quick execution time, making it an excellent choice for APIs, data processing, and event-driven microservices.
  • Community and Support: Fermyon has already an active community and is sustained by a dedicated team focused on the evolving WASM serverless use cases. This makes it a robust option for production applications.

Suborbital Atmo

Suborbital Atmo is the second leading framework tailored for building modular, event-driven applications with WASM. It is “marketed” to enable complex serverless workflows and microservices using WASM.


The strengths of Atmo are the following:

  • Workflow-Oriented: Atmo’s workflow composition capabilities make it stand out for applications that need multi-function workflows, where functions interact and pass data across a sequence.
  • Modular Microservices: Suborbital’s approach to develop microservices using WASM enables highly modular & composable applications, which is handy in cloud-native and distributed systems.
  • Concurrent Execution: Atmo’s task manager allows concurrent processing, which is beneficial for applications that require background processing or high throughput serverless functions.

Conclusions

The serverless paradigm has revolutionized backend development by allowing developers to focus on writing code without worrying about the underlying infrastructure. When combined with WebAssembly, serverless computing becomes even more powerful.

As a result, WebAssembly is likely to become a key technology for serverless computing. Given its potential for efficient, portable, and secure code execution, it could redefine how developers build and deploy applications in cloud and edge environments, making it ideal for emerging computing needs across the cloud.

Îndemnul nostru

Efortul pus în programele pentru studenți completează teoria din facultate cu practica care “ne omoară”. Profitați de ocazie, participând la cât mai multe evenimente!

Acest site folosește cookie-uri și date personale pentru a vă îmbunătăți experiența de navigare. Continuarea utilizării presupune acceptarea lor.