Running TypeScript in WebAssembly on the Cloud
From Author:
Build serverless functions in TypeScript, and then compile them to WebAssembly (Wasm) to be run in the cloud. This is a different model than the original Wasm design suggested, but it is proving to be a powerful concept. In this talk, we dive into the background of Wasm, then look at its broader applications before examining a novel way of building TypeScript code into a Wasm binary for execution in the cloud.
This talk has been presented at TypeScript Congress 2023, check out the latest edition of this JavaScript Conference.
FAQ
WebAssembly is originally a browser-based technology allowing multiple programming languages to compile into a runtime binary format for execution alongside JavaScript. Fermion Technologies extends its use to the cloud due to its fast startup times, small binary sizes, and its secure, cross-platform capabilities.
Serverless computing refers to a cloud computing model where the management of servers is abstracted from the developer. In Fermion's environment, serverless allows developers to focus on writing event-driven applications, such as HTTP requests, without managing traditional server setups like socket servers or TLS certificates.
Spin is an open-source tool developed by Fermion Technologies for building serverless applications. It allows developers to write applications in various languages, compile them into WebAssembly, and run them in a serverless manner on the cloud. Spin supports languages like Rust, Go, Python, JavaScript, and TypeScript.
TypeScript is compiled into WebAssembly using an intermediary method in Spin. The process involves bundling the JavaScript source code and then converting it into WebAssembly, optimizing runtime by preloading the scripting files into the WebAssembly module.
Spin supports top-tier languages such as Rust, Go, Python, JavaScript, and TypeScript, and also handles second-tier languages. It provides features like key value storage, database integrations, and AI inferencing within a simplified developer environment.
To deploy a TypeScript serverless application, use Spin to create an app, build a WebAssembly module from it, and then deploy it locally or onto Fermion Cloud. Spin also supports deployments to Kubernetes clusters, Docker desktop, and other environments.
To start using Spin, visit developer.fermion.com, follow the Quick Start Guide to install Spin, and use commands like 'spin new', 'spin build', and 'spin up' to create and run a serverless application locally. Detailed templates are available for various use cases and languages.
Video Transcription
1. Introduction to WebAssembly and Cloud Runtime
Hi, I'm Matt Butcher, one of the founders of Fermion Technologies. Today we're discussing running TypeScript in WebAssembly on the cloud. WebAssembly is a browser-based technology that allows you to compile different languages to a language-neutral runtime format. It offers fast startup times, small binary sizes, and cross-platform support. We extracted the WebAssembly runtime from the browser and built a cloud runtime.
Hi, I'm Matt Butcher. I'm one of the founders of Fermion Technologies, and today we're going to be talking about running TypeScript in WebAssembly on the cloud. So that's a lot of terms to unpack here.
Let's start really quickly with WebAssembly. So you may be familiar with WebAssembly as a browser-based technology. The original idea was to build a runtime in a binary format in which you could compile lots of different languages to the same language-neutral runtime format and execute it inside the browser, side by side with JavaScript. So, for example, in the case of someone like Figma, they used WebAssembly to take their C++ code, compile it to WebAssembly, and then interact with it from their JavaScript running in the browser.
Now, at Fermion, we took a look at WebAssembly, and what the runtime characteristics of WebAssembly are just right for the cloud. It has very fast startup times, very small binary sizes, the security sandboxing model is great, and of course, it supports cross-platform, cross-architecture, and cross-language. So, we took the WebAssembly runtime, plucked it out of the browser, kinda popped a version into the cloud, and began building a cloud runtime.
2. Introduction to Serverless and Spin
Fermion is a serverless environment that allows you to do away with setting up servers and handling boilerplate code. In serverless, the entry point for the application is the event handler, which takes an HTTP request, handles it, and returns a response. Spin is an open source programming tool and platform that enables you to create serverless applications in multiple languages and run them in a serverless style on the cloud. Spin supports top-tier languages like Rust, Go, Python, JavaScript, and TypeScript, and is focused on providing a simple and easy serverless style of program development.
So the second term we wanna define is serverless. Fermion is a serverless environment. Spin builds serverless applications, but serverless itself is a term that sometimes gets used in really unclear ways. So I wanna make it really clear what I'm talking about when I talk about serverless. What is the server that we are doing without? Well, to me, it's the software server. If you're used to building microservices or other kinds of backend technologies, you know that step one is usually setting up some kind of server, something that'll start a socket server, will open a port, will listen for inbound requests, will handle those requests. You end up writing all kinds of boilerplate code like interrupt handling and TLS certificate loading and all of that kind of stuff. So in serverless, to me, a serverless application is one where we can do away with all of that. Where the entry point for the application is the event handler. So we'll talk primarily about HTTP, though this could equally apply to consuming something off a PubSub queue or dealing with a time-based trigger, but in HTTP, the event is an HTTP request that comes in. You get that request, you handle the request, you return an HTTP response, and you shut down. So there's no setting up a server, there's no setting up TLS certificates, none of that. The serverless environment says you just define an event handler that takes the request and returns a response. So we wanted to take WebAssembly, put it on the server side, and build a serverless framework. To do that, we needed a tool, so we built Spin. Spin is an open source programming tool and, in some ways, a platform that allows you to create serverless applications in a variety of different languages, compile them to WebAssembly, and run them in a serverless style on the cloud. Spin supports as top-tier languages, Rust, Go, Python, and, of course, JavaScript and TypeScript, though it also supports a number of second-tier languages. And we are working on all kinds of tooling to make it easier and easier for you to build an application that is powerful, has key value storage, database, even AI inferencing, but it still follows that very simple, low setup, almost no-op style developer environment, and a very easy serverless style of program development. Primarily, we'll be talking about that.
Comments