Server-Side, Edge and Serverless Wasm

36.1 Why Wasm on the Server?

Fast cold starts (microseconds to milliseconds vs containers' hundreds of milliseconds), density (thousands of instances per host), sandboxing (multi-tenant safety), portability (one binary for x86/ARM), and polyglot (any language that compiles to Wasm).

36.2 Platforms

Fermyon Spin (open source) Framework for Wasm microservices: HTTP triggers, key-value, SQLite, Redis, outbound HTTP, variables. SpinKube for Kubernetes. Fermyon Wasm Functions (Akamai).

wasmCloud (CNCF) Distributed actor/component platform with capability providers and lattice networking (NATS) Cloudflare Workers

V8 isolates. Wasm via Rust (workers-rs), C/C++, and Python Workers (Pyodide) Fastly Compute

Wasmtime-based edge compute (Rust, JS via StarlingMonkey, Go/TinyGo) Vercel / Netlify edge functions Wasm modules inside JS edge runtimes Shopify Functions

Wasm for commerce customization (Rust/JS) Akamai (Fermyon), Wasmer Edge, Golem Cloud (durable Wasm workers) Envoy / Istio (proxy-wasm) Network filters as Wasm plugins

Dapr, Kubernetes (runwasi/SpinKube) Cloud-native integration (Module 39)

36.3 Spin Example (Rust HTTP Component)

spin new -t http-rust hello-spin && cd hello-spin
use spin_sdk::http::{IntoResponse, Request, Response};
use spin_sdk::http_component;
use spin_sdk::key_value::Store;

#[http_component]
fn handle(req: Request) -> anyhow::Result<impl IntoResponse> {
    let store = Store::open_default()?;
    let count = store.get("visits")?.map(|v| String::from_utf8_lossy(&v).parse::<u64>().unwrap_or(0)).unwrap_or(0) + 1;
    store.set("visits", count.to_string().as_bytes())?;
    Ok(Response::builder()
        .status(200)
        .header("content-type", "text/plain")
        .body(format!("Hello from Wasm! {} {} (visit #{count})", req.method(), req.path()))
        .build())
}
spin build && spin up          # http://127.0.0.1:3000
spin deploy                    # deploy to a cloud platform

36.4 wasi:http Components (Portable)

Write against the wasi:http/proxy world, then run with wasmtime serve, Spin, Fastly, wasmCloud, or jco, using the same component across hosts.