Cloud Native 28 min read

Design and Implementation of ByteFaaS Worker: A Lightweight WebAssembly‑Based Serverless Solution

ByteFaaS, ByteDance’s internal function compute platform, leverages WebAssembly to create a lightweight, cloud‑edge integrated serverless solution called ByteFaaS Worker, detailing classic versus lightweight FaaS, the WebAssembly runtime, simplified architecture, traffic scheduling, edge support, developer SDKs, and performance benefits.

ByteFE
ByteFE
ByteFE
Design and Implementation of ByteFaaS Worker: A Lightweight WebAssembly‑Based Serverless Solution

ByteFaaS is ByteDance’s internal function‑as‑a‑service (FaaS) platform that supports both classic container/VM isolation and a new lightweight process‑internal isolation based on WebAssembly. The platform abstracts away resource and operations details, offering automatic scaling, multi‑event source support, and high‑availability, with over 100 k functions deployed and peak traffic of 70 k QPS.

Classic FaaS runs each function in a separate VM or container, providing strong isolation but incurring long cold‑start times, high memory overhead, and scaling latency. ByteFaaS addresses these drawbacks by introducing the "lightweight function" model, where many functions share a single runtime process, reducing cold‑start latency to sub‑millisecond levels and memory usage to a few hundred kilobytes.

The lightweight runtime is built on WebAssembly. WebAssembly offers a portable, safe, and fast execution sandbox that can run code compiled from languages such as C, C++, Rust, Go, and JavaScript. A typical host‑call flow is illustrated below:

// 读取环境变量的值
// 缓存空间的大小需要和 `environ_sizes_get` 返回的大小对齐
pub fn environ_get(arg0: i32, arg1: i32) -> i32;

// 返回对应环境变量的数据长度
pub fn environ_sizes_get(arg0: i32, arg1: i32) -> i32;

WASI provides system‑level APIs (e.g., file I/O, environment variables) that the guest program can invoke via hostcalls. In ByteFaaS, additional capabilities such as HTTP, RPC, KV storage, and logging are exposed through a custom hostcall framework called BytedRing :

// 提交一个 hostcall event
fn submit(event_id: i32, service_provider_id: i32, data_ptr: i32, data_len: i32)

// 非阻塞查询某个 hostcall event 返回状态
fn poll(event_id_ptr: i32, size_ptr: i32)

// 阻塞等待某个 hostcall event 返回
fn wait(event_id_ptr: i32, size_ptr: i32)

// 读取 id=event_id 的 hostcall event 返回的 payload
fn read(event_id: i32, service_provider_id: i32, data_ptr: i32)

Developers can use language‑specific SDKs that wrap these hostcalls. For Go, the SDK (named wago ) provides a simple entry point:

package main

import (
    "example/internal/go/path/faas"
    "example/internal/go/path/faas/http"
)

func main() {
    faas.Start(handler)
}

func handler(_ *http.Request) (resp *http.Response) {
    return &http.Response{
        StatusCode: 200,
        Header: map[string][]string{"Content-Type": {"text/plain"}},
        Body:   http.MustNewBody([]byte("Hello WASM from Golang!")),
    }
}

JavaScript developers can write functions using the @byted/wajs SDK, which mirrors the ServiceWorker model:

import { run } from '@byted/wajs';

const handler = async (request: Request) => {
  return new Response("Hello World", {
    headers: { 'content-type': 'text/plain' },
  });
};

run(handler);

To exploit the lightweight nature, ByteFaaS adopts a simplified architecture that removes unnecessary data‑plane components. Requests arrive at the Gateway, which directly forwards them to the appropriate runtime process, eliminating the multi‑step dispatch chain of classic FaaS. This reduces request latency and improves cold‑start performance.

Traffic scheduling uses a weighted round‑robin algorithm with closed‑loop feedback, dynamically adjusting weights based on real‑time latency and concurrency metrics. The system also supports tenant‑isolated resource pools for privacy‑sensitive workloads.

Cold‑start optimization removes the metadata lookup and code‑download steps by caching function metadata in the Gateway and pre‑distributing code packages. As a result, a typical cold‑start now consists of only gateway routing, runtime loading, and execution, achieving sub‑millisecond total latency.

Edge deployment is a first‑class scenario: ByteFaaS Worker’s tiny memory footprint (≈32 MB per instance) enables dense placement on edge nodes. Global KV and Local Cache services provide low‑latency storage, with Global KV offering eventual consistency across regions and Local Cache delivering ultra‑fast per‑node access.

Developer experience is further enhanced by two tools: a playground that instantly deploys a function and provides a temporary invoke URL with live logs, and a CPU‑profiling integration with ByteDog that captures WebAssembly stack traces for performance debugging.

In summary, ByteFaaS Worker demonstrates how WebAssembly can power a cloud‑native, edge‑ready serverless platform that delivers sub‑millisecond cold starts, high‑density deployment, flexible multi‑language SDKs, and robust operational tooling.

Cloud NativeserverlessEdge ComputingWebAssemblyFunction-as-a-ServiceGo SDK
ByteFE
Written by

ByteFE

Cutting‑edge tech, article sharing, and practical insights from the ByteDance frontend team.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.