The Evolution of Serverless & WebAssembly

An icon of a coffee

Grab a coffee now! This chapter is all “why” and no code, so it’s the perfect place to enjoy it before it goes cold.

Every few years, our industry redraws the line between “your code” and “the machine it runs on.” Physical servers gave way to virtual machines, virtual machines gave way to containers, containers gave us Kubernetes and, eventually, serverless functions. Each step made the unit of deployment smaller, faster to start, and easier to reason about.

WebAssembly is the next step on that line, and this chapter is about why it exists at all.

The Compute Continuum
Figure 1.1. The Compute Continuum

We won’t touch the Spin CLI or its SDKs yet. Before we can appreciate what Spin does for us, we need to be clear about the problems it’s solving and where it helps us. So we’ll do three things:

  1. Look at where containers and traditional Functions-as-a-Service (FaaS) hurt.
  2. Introduce WebAssembly as a genuinely new option: not a replacement for everything, but as the third wave of cloud computing.
  3. Explain why Spin is the framework I reach for when I want to build serverless apps, and why Rust is such a natural fit for it.

By the end of this chapter, you’ll understand the problem domain well enough that every design decision in Spin will feel obvious rather than arbitrary.

That’s the goal.

Where Containers and Traditional FaaS Fall Short

Let me be clear up front: containers are wonderful, and I’m not here to bury them. They solved a real problem (“It works on my machine”), and they did it well enough to reshape the entire industry. However, every tool has a grain. When you push containers in the direction of fine-grained, bursty, event-driven compute, you start rubbing against that grain. Hard.

Containers Carry a Full OS Userland

A container image is your code plus the userland: a base OS layer, system libraries, a language runtime, maybe even a package manager you forgot to strip out. Even a “small” image is tens to hundreds of megabytes; a careless one could be gigabytes. That weight shows up everywhere you’d rather it didn’t:

  • Cold starts. Scheduling a pod, pulling an image, starting a runtime — that’s seconds, not milliseconds, in the unlucky case. If you scale to zero to save money, your users pay for it in latency on the next request.
  • Density. Each container is a process (or several) with its own namespaces and cgroups. You can pack a lot onto a node, but “a lot” is maybe hundreds, not thousands.
  • The security boundary is the whole kernel. A container shares the host kernel and, by default, has broad reach inside its sandbox. Locking it down is a configuration exercise (seccomp, AppArmor, dropped capabilities) that you have to remember to do, correctly, every time.

None of this is fatal for a long-running service that starts once and keeps serving traffic for weeks. It’s death by a thousand cuts for a function that should spin up, handle one request, and vanish.

Traditional FaaS Trades One Problem for Another

Functions-as-a-Service (FaaS), like classic cloud “serverless,” tried to fix the ergonomics. Write a handler, forget the server, scale automatically. Lovely. But under the hood, most FaaS platforms are still provisioning a container or a micro-VM per function, and that means:

  • Cold-start latency is a first-class, well-documented pain. A JVM-based function pulling in a fat dependency tree can take a full second (or more) to answer its first request. Node.js does better, but it’s still hundreds of milliseconds in the general case.
  • Vendor lock-in creeps in through the handler signature, the packaging format, and the proprietary event shapes. Your “portable function” is portable right up until you try to move it to a different FaaS platform or cloud vendor.
  • Idle cost and keep-warm hacks. Because cold starts hurt, teams keep functions warm with synthetic pings, which quietly defeats the scale-to-zero economics that made FaaS attractive in the first place. Cloud vendors provide premium tiers, which keep idle resources allocated to “hide” the cold-start penalty.

Notice the pattern. Containers are too heavy to start instantly; traditional serverless is often built on containers or micro-VMs, so it inherits the weight and papers over it with automation. We keep optimizing the same fundamental unit instead of questioning it.

What Modern Serverless Demands

If we describe the ideal unit of serverless compute from scratch, the wishlist writes itself:

  • Starts in milliseconds, so scale-to-zero has no latency penalty
  • Results in a tiny package, so distribution and cold-pull are cheap
  • Resource-efficient, so a single host can run thousands of distinct workloads
  • Strictly sandboxed, so running untrusted code is safe without a checklist
  • Portable: The same artifact can run everywhere: any CPU, any OS, any cloud, no rewrite

That’s not a description of a container. It’s a description of a WebAssembly component — which is exactly where we’re heading.

WebAssembly Is the Foundation

So what is WebAssembly? The specification gives us a delightfully unglamorous one-liner, and I want to anchor everything on it:

WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine.

Source: webassembly.org

That sentence is doing a lot of work, so let’s unpack the three ideas hiding in it, because each one maps directly to a value we care about on the server and in the cloud.

Binary Instruction Format

Wasm is compiled bytecode, not source and not a language you write by hand (although you can write it by hand using WAT). You write Rust (or Go, or C, or…); a compiler emits a compact .wasm binary.

“Compact” matters: the format was explicitly designed to be small over the wire and fast to decode. This is where the tiny artifact and fast cold start properties begin. To put the real-world impact of this design into perspective, consider how WebAssembly compares to traditional deployments across two critical operational metrics:

Artifact Size: Because WebAssembly components package only your application code and its direct dependencies (stripping away the entire operating system userland, background utilities, and filesystem found in a standard Docker image), the resulting binaries are typically measured in mere megabytes, or even kilobytes.

Comparison of Typical Distribution Sizes
Figure 1.2. Comparison of Typical Distribution Sizes

Cold Start Execution: Without a guest OS to boot or a heavy container network stack to initialize, a runtime like Spin can load, decode, and execute a WebAssembly component in under a millisecond. This near-instant initialization effectively eliminates the notorious cold start penalty also associated with traditional FaaS.

Comparison of Cold-Start Times
Figure 1.3. Comparison of Cold-Start Times

Stack-Based Virtual Machine

The code runs on an abstract stack machine with a defined instruction set, independent of any real CPU. Your amd64 laptop and an arm64 edge node run the same bytes. A runtime like Wasmtime compiles that bytecode to native machine code (ahead-of-time or just-in-time), so you get near-native speed without shipping a native binary per architecture.

Stack-based Virtual Machine
Figure 1.4. Stack-based Virtual Machine

Here’s the part experienced engineers appreciate: before a single instruction executes, the runtime validates the module. It type-checks it and proves that memory accesses and control flow stay in bounds. A malformed or unsafe module is rejected at load time, not caught later with a segfault. Illegal operations at runtime don’t corrupt anything either; they trap, aborting cleanly and reporting the failure to the host. No undefined behavior leaks into your process.

Sandboxed by Default

A Wasm module’s entire world is a single, bounds-checked block of linear memory. It cannot address the host’s memory, another module’s memory, or anything else!

WebAssembly Sandbox
Figure 1.5. WebAssembly Sandbox

And, crucially, a bare module cannot touch files, the network, the clock, or environment variables at all. It can crunch numbers in its sandbox and nothing more, unless the host hands it a capability. That’s WASI, and it takes center stage now.

WASI: Capabilities, Not System Calls

That complete isolation is great for security, but a microservice or serverless workload that can’t read a file or make an HTTP request is just a very secure desk toy. This is exactly where WASI (the WebAssembly System Interface) comes in. Think of WASI as a standardized set of system calls designed specifically for the WebAssembly sandbox. Instead of letting a module talk directly to the operating system, WASI defines a capability-based contract. The host environment acts as a strict gatekeeper: if your WebAssembly application needs to read a config file or open a network socket, the host must explicitly grant that specific capability to the module before execution.

Crucially, WASI gives us POSIX-like system capabilities without tying your code to a specific operating system or architecture. A WebAssembly module compiled against WASI doesn’t care whether it is running on macOS, Linux, or Windows. The interface to files, clocks, and sockets remains identical. With WASI Preview 2 (and the WASI 0.3 ecosystem), this model extends beyond bare system primitives to rich, typed interfaces defined via WebAssembly Interface Types (WIT), allowing modules to import and export high-level capabilities cleanly and safely.

Cross-Platform Portability

Because WebAssembly executes within the stack-based virtual machine, it achieves true portability across hardware, cpu architectures and operating systems. For us as developers, the real magic is what this architecture eliminates from our daily workflow: the dreaded multi-arch build matrix.

If you’ve ever wrestled with docker buildx to deploy a containerized app across Apple Silicon laptops, amd64 cloud clusters, and arm64 edge nodes, you know the pain. WebAssembly completely sidesteps this operational overhead. You compile your application into a single .wasm module exactly once. By leveraging the binary instruction format and WASI to abstract away the underlying CPU and OS, that exact same artifact executes flawlessly anywhere a WebAssembly runtime exists. No cross-compilation configs, no redundant CI pipelines, and zero container bloat.

WebAssembly Portability
Figure 1.6. WebAssembly Portability

The WebAssembly Sweet Spot

Put those properties together, and you get a unit of compute that is genuinely different from what came before — not strictly better, different, with its own sweet spot:

  • Cold start in milliseconds: No OS to boot, no image to pull, and no language runtime to warm. A precompiled module is essentially memory-map-and-go. Scale-to-zero stops being a latency tax.
  • Ultra-dense: An instance is a memory arena plus some bookkeeping, not a process with its own userland. This allows a host to pack far more of them.
  • Portability: Compile once, run anywhere a runtime exists. It’s the JVM’s old promise, but at the bytecode layer, language-agnostic, and with a much smaller trusted computing base.
  • Secure by default: Deny-by-default. Ideal for multi-tenant platforms and for running third-party code you don’t fully trust.
An icon of a gem

You may hear “Wasm is 1000× faster than containers.” Don’t repeat it. The microsecond figure is instantiation time, not end-to-end throughput. For long-running, CPU-bound work, a well-tuned container can match or beat Wasm in a steady state. Be precise, and you’ll be believed! Wasm wins decisively where startup speed and density dominate: short-lived, bursty, event-driven, multi-tenant. That’s a big part of a typical serverless architecture, but it does not encompass everything, and saying so builds trust.

The honest framing — the one I’d stake my reputation on — is this. In 2019, Docker’s co-founder Solomon Hykes said the following on X (previously Twitter):

Source: Solomon Hykes on X
Figure 1.7. Source: Solomon Hykes on X

He wasn’t predicting Docker’s death. He was pointing at the same thing I am: for a large and growing class of workloads, there’s now a lighter, safer, more portable unit than a container.

WebAssembly lays the foundation for the third wave of cloud computing, standing next to VMs and containers, and Spin is how we build on it productively.

Why Spin?

https://leanpub.com/building-serverless-apps-with-wasm-and-spin

What Spin Provides

https://leanpub.com/building-serverless-apps-with-wasm-and-spin

Why Spin Stands Out

https://leanpub.com/building-serverless-apps-with-wasm-and-spin

Why Rust?

https://leanpub.com/building-serverless-apps-with-wasm-and-spin

The Synergy Between Rust and WebAssembly

https://leanpub.com/building-serverless-apps-with-wasm-and-spin

Anatomy of a Spin Component

https://leanpub.com/building-serverless-apps-with-wasm-and-spin

When to Choose Rust

https://leanpub.com/building-serverless-apps-with-wasm-and-spin

Languages Beyond Rust

Spin is language-agnostic by design, allowing you to use any language that can be compiled into a WebAssembly component. At the time of writing this book, Spin provides first-class support for:

  • Rust
  • Go
  • TypeScript / JavaScript
  • Python

Note: The list of supported languages keeps growing as more and more programming languages provide first-class support for WebAssembly, WASI, and the WebAssembly Component Model.

How Interpreted Languages Compile to WebAssembly

You may wonder how Spin turns interpreted languages such as JavaScript or Python into a WebAssembly component.

In the case of JavaScript, your application relies on a specialized, optimized JS runtime called StarlingMonkey. StarlingMonkey is based on SpiderMonkey. It is designed to perform as efficiently as possible within the bounds of a Wasm component.

At compile time, StarlingMonkey, your source code, and all its dependencies are loaded. The global scope is evaluated. At this point, a snapshot is compiled to Wasm and written to disk, resulting in an application that is pre-warmed and ready to serve incoming requests immediately. As a result, JavaScript apps compiled into Wasm components start faster than regular JavaScript.

Polyglot Component Composition

Rust it is for this book, but it doesn’t have to be Rust only!

A Spin application can consist of multiple components. For each component, you can choose a different programming language if you want to, or if a particular language helps you achieve the desired goal in less time or with less code.

Additionally, WebAssembly component composition allows you to stitch together multiple components, regardless of which language was used to implement those building blocks. Instead of juggling multiple languages across components in our sample app, however, I want to teach all necessary concepts clearly and show idiomatic code. Rust lets me do that with the least friction and the most honesty about what’s really happening.


The stage is set. We’ve explored why containers and traditional serverless architectures struggle under modern latency and resource constraints, how WebAssembly changes that equation from first principles, and why pairing Spin with Rust gives us the foundation to build something radically lighter.

Now that the “why” is clear, it’s time to examine the “how.” In the next chapter, we’ll open the hood and explore the core architecture and mechanics that make Spin tick.