WebAssembly for the Backend: GopherCon Israel 2023
This was a rewritten talk for 30minutes prioritizing use case over deep explanation of WebAssembly arch and model. This was given to a lovely crowd of a couple hundred people at GopherCon Israel https://www.gophercon.org.il
to define ABI as protobuf services. 5 e.g. go-plugin gRPC Host Guest Decoupled with gRPC API Decoupled with WebAssembly Monolith Breaking the Monolith Service
tricky to change. For example, Envoy versions are tightly coupled to Istio versions. Dapr is a static binary, so cannot custom libraries dynamically. 6
a contract between the host running wasm and the guest. It defines functions like an IDL. Dapr (golang) supports the http-wasm ABI, implementing the server side of an HttpHandler. Compatible middleware, compiled to wasm, can be replaced without changing Dapr 9
Middleware 3 Dapr Sidecar Request Response My Filter WebAssembly allows custom functionality in a static binary, based on an ABI contract http-wasm guest http-wasm host My Filter http-wasm/http-wasm-guest-tinygo v1.10
for the intended OS + architecture. “FROM scratch” can reduce this to kernel+arch, but only for static binaries. Many applications require a base layer with dependencies like libc, complicating deployment 12
Container integration means pushing a WebAssembly Virtual Machine into the container runtime. For example, wasmer or wasmtime in crun. Some goals of wasm containers is re- use of Dockerfile and OCI registries
CGO 18 WebAssembly isn’t integrated like CGO, but it is safer. github.com/ncruces/go-sqlite3 Not C.CString Not unsafe.Pointer Dynamic not pre- defined in import “C”
config and analysis. Modules are installed locally or via OCI repository. 20 Wasm isn’t just for polygot, it can be a Go plugin implementation! trivy.dev acme-cves.wasm acme-cves.go Tinygo Trivy SDK ghcr.io/acme
varies and is runtime specific. Benchmark! There are other ways to polyglot! 22 • Features like reflection usually don’t work • Wasm has no parallelism, so garbage collection is inline • WebAssembly has no standard library, so binaries can get big. programming WebAssembly is trickier than normal code
compiler has experimental GOARCH=wasm GOOS=js, so of limited use outside node.js and browsers. TinyGo works with WASI, but it lacks features like reflection. @johanbrandhorst proposed a GOOS=wasi compilation target which if accepted increases re-use 24 golang/go#58141
gophers slack! 26 • WebAssembly impacts all layers of architecture, but it is an embedding solution • Go developers can replace some os/exec and CGO patterns with wasm, as well make safe plugins. • WebAssembly is tricky and evolving, so proceed with caution. Here are some good talks: Wasmer Things: An Upside Down Guide To WebAssembly by Edoardo Vacchi CGO-less Foreign Function Interface With WebAssembly by Takeshi Yoneda