Scheduling WebAssembly-backed services with Spin and Nomad

The growing trend of server-side WebAssembly has a very bright future in the cloud-native ecosystem. Because of WebAssembly’s low footprint binary, organizations have the ability to deploy high-performance applications in a secure sandboxed environment with startup speeds that are 1000x that of traditional containers.

The startup time for a WebAssembly runtime is in the 10 milliseconds range, compared to several seconds for a container (or several minutes for a virtual machine), which makes it a good match for serverless — but also for scaling. - Matt Butcher, How WebAssembly Could Streamline Cloud Native Computing

As this trend develops, new methods of scheduling and deploying applications will be needed to mature the server-side WebAssembly ecosystem. In this post, we’re going to show you how you can run the Spin documentation website with Nomad and Spin.

Why choose Nomad?

The obvious question in this instance is why we chose to go with Nomad over something like Kubernetes for this demo. There are a variety of reasons for this architectural decision, but our main thought process relies on Nomad’s ability to handle flexible workload types such as:

The Nomad client also leverages a very simple to use and lightweight binary that enables the same ease of deployment within bare-metal environments as it does in cloud-native environments.

Scheduling WebAssembly-backed services with Spin and Nomad

Let’s get started with our demo now by cloning the demo repo and getting all of our prerequisites out of the way.

Prerequisites

We’ll want to install these applications and make them available on our $PATH. If you’re on Mac or Linux it should be /usr/local/bin and on Windows it’s probably C:\Windows\System32.

You’ll also want to install the Spin binary and install it on your $PATH.

Setup the project

Before we start, we’ll need to clone the Spin repo for the documentation site:

$ git clone https://github.com/fermyon/spin.git

Now let’s get our services started:

$ curl -O https://raw.githubusercontent.com/fermyon/nomad-local-demo/main/run_servers.sh

$ ./run_servers.sh

We’ll also need to set the BINDLE_URL variable in our console:

$ export BINDLE_URL=http://bindle.local.fermyon.link:8088/v1

Running the Spin documentation site with Nomad

To run the documentation site, first we’re going to want to push our application to the bindle registry:

$ git clone https://github.com/fermyon/spin.git
$ cd spin
$ spin bindle push --file spin.toml

And now we should be ready to clone our repo that holds the Job Specification for the Nomad job and run it from the nomad-local-demo repo:

$ git clone https://www.github.com/fermyon/nomad-local-demo
$ nomad run demos/spin/spin-docs.nomad

If everything executes smoothly, the site should be accessible at http://spin-docs.local.fermyon.link:8088

Conclusion

The growth of WebAssembly on the server shows great promise and Fermyon is excited to be part of a community of passionate experts and leaders in this growing ecosystem. We even have a Discord server which is open to the public for anyone who is interested in talking more about the potential of WebAssembly on the server, or just Wasm in general. Come give us a shout!

Join Discord

Interested in learning more?

Get Updates