The Tencent Serverless Cloud Function Custom Runtime allows developers to write serverless functions in any programming language.

In this article, we make the case for serverless functions in Rust and WebAssembly, and demonstrate their use in machine learning and visualization.

You will learn how to create a simple function for machine learning and deploy a serverless web site around it, for free (unless a million people use it!).

First, what is Tencent?

Tencent is the biggest Internet company outside of the USA with over a billion active daily users. Its cloud computing arm, Tencent Cloud, is ranked among the top 5 cloud providers in the world by market share.

If you want to reach the world-wide market with your cloud services, Tencent Cloud should be near the top of your list.

Tencent Cloud is also a leading innovator in serverless computing with strong offerings ranging from Function as a Service (FaaS) runtimes, triggers, connectors, and developer tools.

The Tencent Serverless Cloud Functions (SCF) already support 10+ programming languages and runtime frameworks. But the recently released SCF Custom Runtime took another step forward. The SCF can now support functions written in any programming language.

In this article, I will cover how to run WebAssembly functions, written in Rust, in the SCF.

What we’ll cover in this article

We will first go over the basic concepts. Then, we will review a complete but simple hello world example to deploy your first WebAssembly serverless function.

Finally, we will do something useful with a machine earning as a service (MLaaS) example that takes data and returns the fitted model and visualization in the SVG format.

Here is the final application you will create by the end of this tutorial. It is completely “serverless” and incurs cost when people use it.

The HTML and JavaScript UI can be hosted on any computer including your laptop, and the backend function to perform machine learning and SVG drawing is on Tencent Cloud Serverless.

Why WebAssembly and Rust

Traditional serverless functions are based on heavy-weight frameworks. Developers must write functions in specific application frameworks, such as JavaScript in Node.js or Python Boto and so on.

The Tencent Cloud SCF Custom Runtime breaks this mold, and allows developers to write serverless functions in any language.

To demonstrate this point, it provides examples for a Bash script-based function, a Deno-based TypeScript function, and a Rust-based native binary function. That allows us to create and deploy WebAssembly-based serverless functions on Tencent Cloud.

Why do we want to do that? Here are some reasons.

  • WebAssembly is designed for performance. WebAssembly functions could be 10x faster than comparable programs written in JavaScript or Python.
  • WebAssembly functions are portable. While it is possible to run native binaries on SCF Custom Runtime, those binaries must be compiled to the exact operating system environment for Custom Runtime. It is currently CentOS 7.6 on X86 CPUs, and could change later. WebAssembly functions are portable and very easy to deploy and manage as we will see.
  • WebAssembly functions are safe. It is known that even with Docker, native binary applications could breach the container. Since your application probably depends on many 3rd-party libraries, the risk for rogue code in your dependencies is real. WebAssembly, with its capability-based security model, provides better runtime protection for your code.
  • While WebAssembly is agnostic to programming languages, Rust, AssemblyScript (a subset of TypeScript), C/C++, and Go are among the best languages to write WebAssembly functions. In particular, Rust is a popular and fast rising programming language with a passionate community. It allows us to write highly efficient, yet memory safe, functions.

Finally, programming and deploy WebAssembly functions on Tencent Cloud is actually quite easy. You can do in it an hour. Let’s get started.

#rust #webassembly #serverless #machine-learning #cloud

How to use Rust + WebAssembly to Perform Serverless Machine Learning and Data Visualization in the Cloud
1.95 GEEK