Spin Brings WebAssembly To The Cloud
Written by Nikos Vaggalis   
Tuesday, 07 February 2023

Spin is a new open source framework for building and running cloud microservices with WebAssembly which run on the Fermyon Cloud. Fermyon has also released an SDK for .NET.

First, WebAssembly was touted as a runtime that would be embedded into every major web browser in order to write code in any language that could be compiled to its bytecode format. Because of that, the popular browsers would be able to execute not just JavaScript but also compiled binaries, hence the second property that was attached to it;the Javascript killer. .

As things progressed, both of those assumptions were debunked. WebAssembly has broken loose of the browser's constraints and can be used for running Microservices or serveless functions or even run Wasm binaries on the command line so that even cross-platform CLI applications can be developed. So rather than kill JavaScript it might even interoperate with it.

But back to WebAssembly for the Cloud. Fermyon has made Spin:

a framework for web apps, microservices, and other server-like applications.

Spin provides the interfaces for writing WebAssembly modules that can do things like answer HTTP requests. One unique thing about Spin is that it is a multi-language framework. Rust and Go both have robust support in Spin, but you can also write Python, Ruby, AssemblyScript, Grain, C/C++, and other languages.

With Spin you reduce the overhead of microservices by factoring out the web server (replaced by a WAGI server) and writing out HTTP handlers in whatever language we want (Rust, C, JavaScript, Python, etc), which are then compiled to WebAssembly. The host runtime will provide the features necessary, such as a filesystem (a highly sandboxed one), outbound HTTP, key/value storage, etc. Therefore we can focus our microservices on handling the business logic, leaving the underlying platform to manage all of the HTTP, SSL Certificates, and so on.

With Spin you also satisfy the necessary requirements that need to be in place for Cloud computing applications:

  • Strong security
  • Small binary size
  • Fast loading and running
  • Support for many OSes and architectures
  • Interoperability with cloud services

Here’s what a Spin “Hello World” looks like written in Rust:

#[http_component]​
fn hello_world(_req: Request) -> Result<Response> {​
Ok(Response::builder()​
. status(200)​
. body(Some("Hello, Fermyon!". into()))?)​
}​

Writing a Spin module is not much different in Go:

func main() {
spin. HandleRequest(func(w http. ResponseWriter, r *http. Request) {
fmt. Fprintln(w, "Hello, Fermyon!")
})
}

Spin v0. 7. 0 version of the framework released last month comes with:

  • HashiCorp Vault integration for secrets
  • Support of connecting to MySQL databases from Spin applications.
  • New Spin SDKs for JavaScript and TypeScript

Fermyon has also released an SDK for . NET which can be used to:

  • Build Web applications and microservices using the Spin executor
  • Send HTTP requests to external hosts
  • Read and update Redis stores
  • Query and update PostgreSQL databases

So there you have it, WebAssembly as a better, lighter alternative to VM's, containers and Kubernetes.

 

More Information

Fermyon Spin

Introducing Spin

A simple URL shortener built with Spin

Related Articles

How Is WebAssembly Doing?

Blazor WebAssembly Crash Course

WebAssembly Explorer - A Learning Tool

WebAssembly Is Ready For Use

WebAssemby Another Milestone 

WebAssembly Takes A Big Step Towards Being Real 

Progress On WebAssembly 

WebAssembly Has Mozilla, Microsoft,Apple and Google Backing It 

 

 

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Save On edX Professional Certificates
16/10/2024

The idea of gaining a Professional Certificate is to demonstrate your possession of skills needed to succeed in today's most in-demand fields. News of 30% off edX Professional Certificates prompted us [ ... ]



Java Version 23 Released
30/09/2024

It was in April 2024 that we had Java 22. Now after just 6 months there's version 23, which is a STS release with lots of features in preview status.


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Thursday, 16 February 2023 )