WebAssembly apps: Build and run them in the cloud with Fermyon and Spin 2.0

Fermyon is a platform that provides an environment for the development, deployment and management of app WebAssembly (WASM) based on the cloud. It is designed to simplify the application development and deployment process, exploiting the potential of WebAssembly to achieve efficiency, portability and security at the highest levels.

Spin 2.0 is a framework integral to the Fermyon platform that helps you build quickly serverless applications taking advantage of the features offered by WebAssembly. The latter, as we have explained in other insights, is a technology that allows you to compile the code in a lightweight and fast binary format. WebAssembly is supported in all web browsers – why not make smart use of it to create apps that can operate efficiently and scalably?

The developers of Spin 2.0 introduced the concept of componentsobjects that act as a “wrapper” around the modules core WASM (in another article we saw what WASM is and why it is revolutionizing web applications). Components can communicate with each other within one .wasm binary filewithout resorting to API calls.

With Spin 2.0 it is possible join different components forming a larger one. The proposed scheme promotes better isolation between components allowing the communications via predefined interfaces.

The benefits of Spin 2.0 for building WebAssembly apps

Already from these first lines, who is used to develop for the web, will have already understood the advantages of Spin 2.0. There WASM technology is gaining ground in numerous IT sectors. Spin allows you to build web applications, software full-stack and programs with artificial intelligence abilities such as WebAssembly components.

The applications that can be obtained using Spin are:

  • Of dimensions clearly inferior compared to the images of classic containers;
  • completely portable on different operating systems and architectures (different CPUs for ISA, Instruction Set Architecture);
  • capable of guaranteeing a latency incredibly low at start-up;
  • capable of handling tens of thousands of requests per second;
  • capable of working anywhere, from the smallest devices such as i single-board computer Raspberry Pi, a Docker Desktop, passando per Kubernetes, Nomad e Fermyon Cloud.

Spin guides users in creating, compiling, deploying and running server-side applications with WebAssembly. Thanks to simple commands like spin new, spin build e spin upyou can start your development journey without any friction.

Spin 2.0 capabilities and performance

When developing WebAssembly applications, developers can take advantage of a wide range of features, including the ability to communicate with external systems.

Persistence services are directly integrated into Spin 2.0: this means that the WebAssembly application execution environment allows the applications themselves to save and retrieve data in various forms without having to install or configure external services. With the built-in storage solution, for example the one based on SQLite, you can save and read data in the key-value format. However, support is assured for external databases come MySQL e PostgreSQL.

Vault it is the management and storage functionality of the dynamic variables used by each application. The system, also integrated into the Spin 2.0 framework, offers a secure and centralized infrastructure for the management of application variablesoften used for sensitive configurations, storing credentials, access keys and other critical data.

The WASM components that can be developed with Spin 2.0 can also communicate with external systems via API HTTP. Furthermore, direct support for operations is provided artificial intelligencesuch as large language model (LLM) inferences and natural language content generation.

Per install Spin 2.0 simply follow the instructions for Linux, macOS and Windows on the page Installing Spin.

How to create a new WebAssembly project

The command spin new allows you to start the creation of a new project or application within the Spin 2.0 development environment. It can be used for generate the basic structure of the project, preparing files, folders and other essential resources.

Spin 2.0 features several predefined templates, each developed with a different programming language. The framework supports several languagesamong which JavaScript/TypeScript, Python, .NET, Rust e Go. It also adheres to the standard WASIwhich means that dozens of languages ​​that support WASM can be compiled, built, and run directly.

spin new

WebAssembly System Interface (WASI) is a standard that aims to define a standardized interface between WebAssembly programs and the host on which they run. WASI provides a set of APIs and specifications to allow WebAssembly to interact, for example, with various system resources such as file system, network and so on.

The next steps are quite intuitive and involve assigning a name and description to the application under development. The setting HTTP path corresponds to the path that allows you to invoke the application and the WASM components that compose it.

Typing cd followed by the name of the path containing the application model, you can check all files generated by Spin 2.0. Assuming you use Visual Studio Code as editorjust type code . to automatically open all files in the folder.

File template app WebAssembly

Il file manifest spin.toml

Every single application created with Spin 2.0 contains a file called spin.toml: houses the app’s identifying information, the list of actions it should initiate in response to specific triggerthe WASM modules used together with their configurations.

Checking the source code of the application, you immediately realize what each example module created with the command does spin new. In the example, we see simple code Rust who responds with the message Hello World! to any incoming connection request received via HTTP.

Example WebAssembly (WASM) app in Rust

Then typing the commands spin build e spin up it is finally possible fill out the application in WebAssembly and then launch it locally.

By connecting from a browser with the indicated localhost address, in this case you obtain – as a response – the very string Hello World!

Run WebAssembly apps

Cloud publishing with Fermyon

So far we have seen three simple commands that allow you to create, modify, compile and run WebAssembly applications locally starting from code written in any programming language. With a fourth command, that is spin deployyou have the opportunity to to publish the app developed on cloud making it accessible from any remote system.

Fermyon Cloud allows you to manage up to 5 applications for free WASM with as many custom domains. It also allows you to process up to 100,000 requests monthly. It also delivers 5 GB of SQLite space to store your databases and 1 GB of storage key-value. All without paying a single cent.

In a matter of moments, using the simple command spin deploythe application created with Spin 2.0 will be published on the cloud and made accessible tomnemonic address indicated (freely customizable, as highlighted previously).


Please enter your comment!
Please enter your name here