Hacker News new | ask | show | jobs
by slinkydeveloper 345 days ago
At Restate.dev (workflow as a code engine) we use Rust/WASM to code-share the implementation of the durable execution protocol between the restate-server and the SDKs to develop workflows. This code is essentially a "pure" state machine: events in, events out, no side effects.

We use WASM in some cases:

* Our Typescript SDK uses wasm-bindgen to compile and release the Rust part of the code. We have chosen WASM over Node native extensions because we wanted to support deno, cloudflare workers, bun, and potentially other runtimes. We've stumbled on few issues related to packaging, but except that it was a smooth process.

* Our Golang SDK uses WaZero + manual bindings using protobuf's. It was a bit of a manual process to set it up, especially surrounding concurrency issues wrt accessing the WaZero runtime plus you need some wasm runtime pooling to get decent performance, but at the end it works well and reliably.

My lesson learned from our experience is that Rust is the real player here, because it delivers on the promise that you can develop libraries that can be easily embedded in high level languages. It's really "write once, bind everywhere".

WASM is just a "packaging"/"distribution" detail in our case, and we picked it just for lack of alternatives. For example in our Python SDK, we could have used WASM but we didn't, instead we went with PyO3 which is an amazingly well done Python -> native code bindgen, and it works without hassle for users as opposed to, for example, CGO in Golang. If Golang had a PyO3-like solution without CGO/any hassle for users, I would have taken it as opposed to doing the WASM bindings myself.

Plus, from what I've tried myself, the whole WASM experience is great only when used in combination with TS/wasm-bindgen, in the other scenarios it's a lot of manual tedious memory moving code involved. Maybe when WIT gets more broadly adopted, and there will be bindgens available in most languages/engines, this will be different.

If you wanna check out the projects and see how it works: https://github.com/restatedev/sdk-shared-core/, https://github.com/restatedev/sdk-go/ and https://github.com/restatedev/sdk-typescript/