Watch: Building Microservices with Wasm, Rust, and Spin
Radu Matei recently presented at Rust Linz. His talk, “Building Microservices with WebAssembly, Rust, and Spin” begins with an introduction to WebAssembly. Then Radu talks about the Wasm component model before he dives into using Spin to create a new application.
What is WebAssembly
Radu talks about WebAssembly as a binary instruction format for a stack-based virtual machine. But it’s not a format we directly write. Rather, the best way to think about WebAssembly is as a compilation target for other languages.
Originally developed for the browser five years ago, it is the technology behind web versions of AutoCAD, Google Earth, and others. But WebAssembly has some attractive virtues:
- Cross-platform and cross-architecture support (compile once, and run on a wide variety of OSes and architectures)
- Compact binary format
- Security isolation sandbox
- Fast startup times
These virtues that are good for the browser actually make it a great fit for server-side and cloud scenarios. WASI provides a system interface to allow non-browser WebAssembly binaries to access files, environment variables, and so on in a secure way.
The Component Model
Radu talks about WebAssembly using an analogy of the operating system. WebAssembly binaries are composed of the low-level instructions. And WASI provides access to networking, file system, and other low-level system resources. But there’s a third thing needed.
The component model (which is in development) represents the process model. It defines how processes are started and how they communicate.
The component model is focused on three things: host-embedding components (e.g. plugins), component composition (re-using components), and runtime dynamic linking (choosing at runtime which components best match the situation). Rust already has some great tooling to work with components. Check out the video for Radu’s walk through a few examples.
Spin and Components
Spin is a framework for building and running event-driven microservices and web apps with WebAssembly components. It makes use of the component model, and is simple and easy to develop.
Radu demos using Spin to write HTTP-based event handlers. While Spin applications can be built in a wide variety of languages, Radu builds one using Rust. (After all, this is the Rust Linz meetup.) In the video, Radu walks through the manifest, showing how to define components and map those components to request handlers. From there, he dives into the Rust code and then demos how it works.
Not to be left out, Finicky Whiskers is a great example of building a multi-microservice Spin application. Radu walks through the architecture as an example of how to go beyond the “Hello, World” case.
We’ve talked many times on this blog about our excitement over WebAssembly, the component model, and Spin applications. Radu’s Rust Linz presentation is a great and succinct overview of how those things all tie together in Fermyon’s vision for building the next wave of cloud computing.
The Rust Linz meetup is a great source within the Rust community. Head over to their site and take a scroll through their “Previous talks” section for a variety of deeply informative Rust presentations.