Skip to content

Module 3.9: WebAssembly and Cloud Native

Complexity: [MEDIUM] - Conceptual awareness

Time to Complete: 25-30 minutes

Prerequisites: Module 3.1 (Cloud Native Principles), Module 3.3 (Cloud Native Patterns)


After completing this module, you will be able to:

  1. Explain what WebAssembly is and how WASI extends it for server-side use
  2. Compare Wasm workloads with containers in terms of startup time, size, and security isolation
  3. Identify where Wasm fits in the cloud native landscape alongside containers
  4. Evaluate use cases where Wasm provides advantages over traditional container runtimes

WebAssembly (Wasm) is the most significant new runtime technology since containers. Originally built for browsers, it is now breaking into server-side and cloud native computing. Wasm workloads start in milliseconds, weigh kilobytes, and run in a secure sandbox. KCNA expects you to understand where Wasm fits in the cloud native landscape and how it relates to containers.

“If WASM+WASI existed in 2008, we wouldn’t have needed to create Docker.”Solomon Hykes, co-founder of Docker (2019)

That quote shook the container world. It does not mean containers are going away — it means Wasm solves some of the same problems, sometimes better.


┌─────────────────────────────────────────────────────────────┐
│ WEBASSEMBLY (WASM) │
├─────────────────────────────────────────────────────────────┤
│ │
│ Portable, compact BYTECODE format │
│ │
│ Originally: Run near-native code in web browsers │
│ Now: Run anywhere — servers, edge, IoT, cloud │
│ │
│ Key Properties: │
│ ───────────────────────────────────────────────────────── │
│ │
│ PORTABLE Compile once, run on any Wasm runtime │
│ (like Java bytecode, but lighter) │
│ │
│ FAST Near-native execution speed │
│ Millisecond cold starts (not seconds) │
│ │
│ SECURE Sandboxed by default — no file/network │
│ access unless explicitly granted │
│ │
│ COMPACT Binaries measured in KB, not MB or GB │
│ │
│ POLYGLOT Compile from Rust, Go, C/C++, Python, │
│ JavaScript, and more │
│ │
└─────────────────────────────────────────────────────────────┘

Wasm in the browser can talk to the DOM. But on a server, it needs access to files, network, clocks, and environment variables. That is what WASI (WebAssembly System Interface) provides.

Think of WASI as “POSIX for Wasm” — a standard interface between Wasm modules and the host operating system, but with a capability-based security model where each permission is explicitly granted.

┌─────────────────────────────────────────────────────────────┐
│ Your Code (Rust, Go, etc.) │
│ │ │
│ ▼ compile │
│ Wasm Binary (.wasm) │
│ │ │
│ ▼ runs on │
│ Wasm Runtime (WasmEdge, Wasmtime, etc.) │
│ │ │
│ ▼ talks to OS via │
│ WASI (file access, network, env vars) │
│ │ │
│ ▼ │
│ Host Operating System │
└─────────────────────────────────────────────────────────────┘

Pause and predict: Docker’s co-founder said “if WASM+WASI existed in 2008, we wouldn’t have needed to create Docker.” Containers start in seconds and include a full OS userspace. Wasm modules start in milliseconds and are kilobytes in size. In what scenarios would this dramatic difference in startup time and size actually matter?

This is the comparison KCNA is most likely to test. Know the trade-offs.

AspectContainers (OCI)WebAssembly
Startup timeSecondsMilliseconds
Binary sizeMBs to GBsKBs to low MBs
Security modelShares host kernel, needs isolation layersSandboxed by default, capability-based
PortabilityRuns on same OS/arch (or multi-arch builds)True “compile once, run anywhere”
Ecosystem maturityVery mature — huge library of imagesEarly stage — growing fast
Language supportAny language (full OS in container)Growing but not all languages supported well
System accessFull (unless restricted)Explicitly granted via WASI
Use casesGeneral-purpose applicationsFunctions, edge, plugins, lightweight services
OrchestrationKubernetes, Docker SwarmEmerging (SpinKube, runwasi)
┌─────────────────────────────────────────────────────────────┐
│ STARTUP TIME COMPARISON │
├─────────────────────────────────────────────────────────────┤
│ │
│ Container: ████████████████████████████████ ~1-5 seconds │
│ Wasm: ██ ~1-5 ms │
│ │
│ IMAGE SIZE COMPARISON │
│ ───────────────────────────────────────────────────────── │
│ Container: ████████████████████████████████ 50-500 MB │
│ Wasm: █ 0.1-5 MB │
│ │
│ This matters for: │
│ • Serverless (cold start penalty) │
│ • Edge computing (limited storage/bandwidth) │
│ • Scale-to-zero (restart cost must be low) │
│ │
└─────────────────────────────────────────────────────────────┘

Key insight for KCNA: Wasm does not replace containers. They are complementary. Use containers for complex, full-featured applications. Use Wasm where startup speed, size, and sandboxing matter most.

Exercise: Classify the Workload

Review the following 5 scenarios. Would you choose Containers or WebAssembly for each?

  1. A massive legacy Java Spring Boot monolith connected to an Oracle database.
  2. A lightweight image-resizing function that executes thousands of times per second and scales to zero when idle.
  3. A multi-tenant SaaS platform where untrusted customer-provided code snippets need to run safely without accessing the host network.
  4. A stateful PostgreSQL database requiring heavy disk I/O and specific Linux kernel tuning.
  5. A tiny data-parsing microservice deployed to a Raspberry Pi on a constrained edge network with limited bandwidth.
Reveal Answers & Reasoning
  1. Containers: Complex, legacy, heavy applications with deep OS dependencies and specific library requirements are best suited for traditional containers.
  2. WebAssembly: The millisecond cold-start times and tiny footprint make Wasm ideal for high-volume, scale-to-zero functions where container startup latency would be unacceptable.
  3. WebAssembly: Wasm’s default-deny capability-based sandboxing provides excellent, fast isolation for untrusted third-party code execution.
  4. Containers: Databases require deep OS integration, mature storage drivers, and heavy I/O performance that the Wasm and WASI ecosystems do not yet fully support.
  5. WebAssembly: The extremely small binary size and architecture-neutral nature of Wasm make it perfect for constrained edge devices where bandwidth and storage are at a premium.

A Wasm runtime executes .wasm binaries, similar to how a container runtime (containerd, CRI-O) runs container images.

RuntimeKey Characteristics
WasmtimeReference implementation by Bytecode Alliance; production-grade, standards-focused
WasmEdgeCNCF Sandbox project; optimized for edge and cloud native; supports networking and AI extensions
SpinDeveloper framework by Fermyon; build and run serverless Wasm apps easily
wasmCloudCNCF Sandbox project; distributed platform for building Wasm applications with a component model

For KCNA: Know that WasmEdge and wasmCloud are CNCF projects. You do not need to know runtime internals.


Running Wasm workloads on Kubernetes is possible today through containerd shims — the same interface containers use.

┌─────────────────────────────────────────────────────────────┐
│ WASM ON KUBERNETES │
├─────────────────────────────────────────────────────────────┤
│ │
│ How containers run on K8s: │
│ ───────────────────────────────────────────────────────── │
│ kubelet → containerd → runc → Linux container │
│ │
│ How Wasm runs on K8s: │
│ ───────────────────────────────────────────────────────── │
│ kubelet → containerd → runwasi → Wasm runtime │
│ │
│ Same kubelet, same containerd, different shim! │
│ │
│ Key Projects: │
│ ───────────────────────────────────────────────────────── │
│ │
│ runwasi containerd shim that runs Wasm instead of │
│ Linux containers. Drop-in replacement for runc │
│ │
│ SpinKube Run Spin (Wasm) apps on Kubernetes using │
│ custom resources. Manages Wasm apps like K8s │
│ manages containers │
│ │
│ Both use RuntimeClass to tell K8s "this Pod runs Wasm" │
│ │
└─────────────────────────────────────────────────────────────┘

Kubernetes uses RuntimeClass to select which runtime handles a Pod. A cluster can run both container Pods and Wasm Pods side by side:

┌──────────────────────────────────────────┐
│ Kubernetes Cluster │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Container Pod │ │ Wasm Pod │ │
│ │ runtimeClass: │ │ runtimeClass:│ │
│ │ (default) │ │ wasmtime │ │
│ │ │ │ │ │
│ │ containerd │ │ containerd │ │
│ │ → runc │ │ → runwasi │ │
│ │ → Linux │ │ → Wasmtime │ │
│ └──────────────┘ └──────────────┘ │
│ │
└──────────────────────────────────────────┘

Exercise: Design the RuntimeClass Architecture

Imagine you are architecting an e-commerce application on Kubernetes. You have three components:

  1. payment-processor: A complex Java application managing core database transactions.
  2. tax-calculator: A lightweight Rust function that calculates local taxes instantly based on a zip code.
  3. recommendation-engine: A Python service utilizing a massive, specific GPU-bound machine learning library.

Sketch out which Pods would use the default container runtime and which would use a Wasm RuntimeClass.

Reveal Architecture
  • payment-processor: Default container runtime. Needs the mature Java ecosystem, standard JVM profiling tools, and full OS networking capabilities.
  • tax-calculator: Wasm RuntimeClass (e.g., runtimeClassName: wasmtime). Perfect for Wasm: it is a fast, stateless, isolated function written in Rust that benefits from millisecond scaling during checkout surges.
  • recommendation-engine: Default container runtime. Needs direct hardware access (GPU) and complex Python machine learning libraries, which are currently difficult to compile and run efficiently within a restricted Wasm sandbox.

Stop and think: You just learned that Kubernetes uses containerd shims and RuntimeClass to run Wasm. What does this architectural decision tell you about how Kubernetes handles extensibility, and what is the practical impact for cluster operators?

Reveal Analysis

This demonstrates that Kubernetes was designed with strong abstraction boundaries. Because the kubelet talks to a standardized interface (CRI - Container Runtime Interface), it doesn’t actually care if the underlying workload is a Linux namespace, a Windows container, a VM (like Kata Containers), or a Wasm module. The practical impact is massive: operators do not need to build, maintain, and secure a separate “Wasm cluster.” They can run Wasm side-by-side with containers on the exact same nodes, leveraging the exact same Kubernetes APIs (Deployments, Services, Ingress) they already know.


Use CaseWhy Wasm Excels
Serverless functionsMillisecond cold starts make scale-to-zero practical
Edge computingTiny binaries, low resource requirements, runs on constrained devices
Plugin systemsSafe sandboxing — plugins cannot access host unless permitted
Short-lived request handlersNo startup penalty, minimal overhead
Multi-tenant isolationEach Wasm module is sandboxed without needing full container isolation
Use CaseWhy Containers Are Better
Complex applicationsFull OS libraries, mature debugging tools, broad language support
Database serversNeed direct hardware access, complex system calls
Apps needing mature ecosystemContainer images exist for almost everything; Wasm ecosystem is still growing
Heavy I/O workloadsWASI I/O is still maturing compared to native Linux I/O
Legacy applicationsRecompiling to Wasm is non-trivial for large codebases

Wasm is not just theoretical. Several major platforms have already rebuilt their infrastructure around it to achieve massive scale:

  • Shopify: Rebuilt their application extension platform using WebAssembly. Previously, they allowed third-party developers to run custom logic, but it required heavy, slow, and expensive infrastructure. By moving to Wasm, they achieved execution times under 5ms, allowing untrusted third-party code to run safely synchronously during the checkout process without slowing down the user experience.
  • Fastly Compute: Built their entire edge computing platform on Wasm. By bypassing traditional container orchestration entirely, they achieved cold start times of ~35 microseconds (not milliseconds—microseconds). This allows them to instantiate a secure sandbox, run the function, and tear it down for every single request.
  • Cloudflare Workers: Uses V8 isolates (closely related to the Wasm ecosystem) and natively supports executing Wasm modules. This allows developers to write high-performance image rendering or cryptography logic in Rust, compile to Wasm, and execute it across hundreds of edge locations globally with zero cold-start penalty.

Migration Reality Check

While the metrics above are impressive, adopting Wasm today is not as simple as running docker build. Teams migrating to Wasm often encounter severe tooling pain points:

  • Language Support: Rust, C++, and Zig work perfectly. Go’s TinyGo compiler is excellent, but standard Go produces bloated Wasm binaries. Python and JavaScript run by embedding their entire interpreters inside Wasm, which negates the size benefits.
  • Debugging: When a container crashes, you can kubectl exec into it and run top or cat /var/log/syslog. When a Wasm module crashes, you often get a cryptic memory trap error. The debugging ecosystem is still in its infancy.
  • Networking: WASI networking is still evolving. If your application relies on complex socket manipulation or specific HTTP client libraries, compiling to Wasm often fails due to missing system interfaces.

The Wasm Component Model is an emerging standard that lets Wasm modules compose together, regardless of the language they were written in:

┌─────────────────────────────────────────────────────────────┐
│ Rust component ──┐ │
│ ├──→ Composed application │
│ Go component ────┤ (linked at the Wasm level, │
│ │ not at the OS/container level) │
│ JS component ────┘ │
└─────────────────────────────────────────────────────────────┘

This is still early, but it represents a fundamentally different approach to building distributed systems — composing at the module level rather than the container level.


  • All major browsers ship a Wasm runtime — Chrome, Firefox, Safari, and Edge all run Wasm natively. It is the fourth official web language alongside HTML, CSS, and JavaScript. This browser heritage is why Wasm is so portable and secure — it was designed to run untrusted code safely.

  • Wasm binaries are architecture-neutral — Unlike container images that need separate builds for amd64 and arm64, a single .wasm file runs on any architecture. No multi-arch builds, no platform-specific images. This is especially valuable for edge computing where you might deploy to x86 servers, ARM devices, and RISC-V boards.

  • Fermyon ran 5,000 Wasm apps on a single node — In benchmarks, a single Kubernetes node ran thousands of Wasm microservices simultaneously, compared to dozens of containers. The tiny footprint and fast startup make density dramatically higher.


MistakeWhy It HurtsCorrect Understanding
”Wasm replaces containers”Leads to wrong architectural decisionsWasm complements containers — use each where it fits best
”Wasm is only for browsers”Misses the server-side revolutionWASI enables Wasm to run anywhere: servers, edge, cloud, IoT
Thinking any app can be compiled to WasmNot all languages/libraries support Wasm well yetRust and Go have good support; complex C++ apps with many system calls are harder
Ignoring the ecosystem gapBuilding on immature tooling causes painContainer ecosystem (images, registries, debugging) is far more mature today
Confusing Wasm runtimes with container runtimesThey solve different problemsWasm runtimes (Wasmtime, WasmEdge) execute .wasm bytecode; container runtimes (runc, crun) manage Linux namespaces/cgroups

1. You are explaining WebAssembly’s origins to a backend developer who only knows it as a modern cloud-native technology. What was its original design purpose?

A) Replacing Docker containers B) Running near-native code safely inside web browsers C) Accelerating GPU computing workloads D) Optimizing database query execution plans

Answer

B) Running near-native code safely inside web browsers. WebAssembly was originally created to run performance-sensitive code (like games, 3D rendering, and video editing) within web browsers at near-native speed. It was designed as a secure, sandboxed bytecode format that could execute alongside JavaScript. Its adoption in server-side and cloud native computing came later, once developers realized that a fast, secure, portable sandbox was exactly what modern cloud infrastructure needed.

2. Your Rust application compiled to WebAssembly needs to read a configuration file from the host filesystem. By default, Wasm cannot do this because it is strictly sandboxed. What standard makes file access possible?

A) A Wasm-based container image format B) A web framework for building Wasm apps C) WASI (WebAssembly System Interface) D) A Kubernetes controller for Wasm workloads

Answer

C) WASI (WebAssembly System Interface). By design, WebAssembly executes in a restricted sandbox with no access to the outside world. WASI provides a standardized, capability-based API between the Wasm module and the host operating system. It acts as a “POSIX for Wasm,” allowing the runtime to explicitly grant granular permissions for file access, network connections, and environment variables without compromising the security model.

3. Your platform team wants to add Wasm support to an existing Kubernetes cluster that currently runs Linux containers. How do they achieve this without building a separate, dedicated Wasm cluster?

A) A separate Wasm cluster is technically required by the Kubernetes API B) Using runwasi as a containerd shim, and selecting it via a RuntimeClass on the Pod C) By converting the Wasm binary into an OCI container image first D) By replacing containerd with Wasmtime across all worker nodes

Answer

B) Using runwasi as a containerd shim, and selecting it via a RuntimeClass on the Pod. Kubernetes abstracts the container runtime through the Container Runtime Interface (CRI). By installing a shim like runwasi under containerd, the kubelet can schedule Wasm workloads just like standard containers. The operator simply defines a RuntimeClass object, and developers specify runtimeClassName in their Pod spec to route the workload to the Wasm engine, allowing both to run side-by-side on the same node.

4. Your organization’s architecture board mandates using only CNCF-hosted projects for core infrastructure. Which Wasm runtime meets this strict requirement?

A) Wasmtime B) Spin C) WasmEdge D) Docker

Answer

C) WasmEdge. WasmEdge is a CNCF Sandbox project specifically optimized for edge and cloud native use cases, meeting the organization’s governance requirements. While Wasmtime is an excellent production-grade runtime, it is governed by the Bytecode Alliance, not the CNCF. Spin is a framework developed by Fermyon, and Docker is primarily focused on containerization rather than being a pure Wasm runtime.

5. A financial services company is building a scale-to-zero trading algorithm that must execute immediately when a market event occurs. Why might they choose WebAssembly over traditional containers for this specific function?

A) Wasm natively supports advanced financial mathematics libraries B) Wasm modules start in milliseconds, eliminating the multi-second cold start penalty of containers C) Wasm has a more mature ecosystem of pre-built trading algorithms D) Wasm bypasses the Linux kernel’s network stack entirely

Answer

B) Wasm modules start in milliseconds, eliminating the multi-second cold start penalty of containers. Serverless functions that scale to zero must spin up instantly when a request arrives to avoid latency spikes. Traditional containers require spinning up a Linux namespace and OS userspace, which often takes 1-5 seconds. Because WebAssembly only requires initializing a lightweight sandbox and executing bytecode, it achieves cold starts in 1-5 milliseconds, making it ideal for event-driven, instantaneous execution.

6. Your CTO reads an article claiming “Wasm is the new Docker” and asks you to plan a migration of your entire monolithic Java backend and PostgreSQL database to WebAssembly. What is the most architecturally sound response?

A) “We can start the migration immediately, as Wasm runs all Java and database workloads faster.” B) “Containers are always better than Wasm, so we should ignore the article entirely.” C) “Wasm and containers are complementary. Wasm is great for fast, edge functions, but containers are still the right choice for complex apps and databases.” D) “We just need to package the Wasm binaries inside Docker containers.”

Answer

C) “Wasm and containers are complementary. Wasm is great for fast, edge functions, but containers are still the right choice for complex apps and databases.” WebAssembly does not replace containers; it solves different architectural problems. Complex monolithic applications and heavy stateful workloads like PostgreSQL rely on deep OS integration, mature storage drivers, and heavy I/O performance that Wasm cannot currently provide. Conversely, containers carry heavy overhead that makes them suboptimal for tiny edge functions, meaning a hybrid approach is the most effective cloud native strategy.


  • WebAssembly is a portable bytecode format — originally for browsers, now expanding to server-side and cloud native
  • WASI provides system access (files, network) with capability-based security
  • Wasm vs containers: faster startup (ms vs s), smaller (KB vs MB), sandboxed by default — but less mature ecosystem
  • Wasm runtimes: Wasmtime, WasmEdge (CNCF), Spin, wasmCloud (CNCF)
  • Wasm on K8s: runwasi shim + RuntimeClass lets Wasm and containers coexist
  • Best for: serverless, edge, plugins, multi-tenant isolation
  • Not ready for: complex apps, heavy I/O, legacy migrations
  • Wasm complements containers — it does not replace them

Module 3.10: Green Computing and Sustainability - How cloud native practices intersect with environmental sustainability and carbon-aware computing.