Ludwig

Zig vs Rust at work: the choice we made

Intro

At [redacted], we serve hundreds of millions of users. We use C and C++ in some of our core systems which end up servicing some of our most important features.

For context, when this discussion started: there was about 100 LOC of Zig at that point in the codebase, and a single service in Rust(an edge-distributed API compiled to WASM).

Throughout 2023, there was a discussion on Rust vs Zig and what to adopt based on our needs. Keep that in mind as Zig moves fast, and some of the arguments against it are already things of the past.

To make it incredibly simple, our needs boiled down to:

Spoiler: we ended up choosing Zig. I won't go into too much details: I am mostly sharing that because I think that it gives a great insight as to the kinds of considerations that take place in a company where your code must run on a huge variety of targets and that might be ran by 100s of millions of users. I think the convo shows well that "fast code" or "memory safety" aren't the only factors to be considered.

What follows is a bit of an amalgamation of the discussion we had over the months -- they do not reflect my own opinions. I was mostly following along these discussions, and had already settled for Rust for my own team due to our specific needs. Also, some of it is wrong! Or idealistic! Everyone in the convo either loved Rust, Zig or both, and everyone wanted to make sure we made the right choice.

On the importance of C interop at [redacted] in the [redacted] team

The library we intended to rewrite had potential to be used on every platform we are on. We're pretty much on every platform: web, mobile, VR headsets, gaming consoles, on desktop. The only way to guarantee we can run on all these platforms is to provide a C API and use it via FFI. We also had other libraries which we wanted to be able to glue and build together with the one we were aiming to rewrite.

The main arguments

For rust

On C interop with Rust:

For Zig

Conclusion

Zig significantly reduced the time and effort required to port our existing codebases and to ensure compatibility across all our platforms. The team couldn't be convinced Rust would make it as simple.

I did not go into a lot of the details, PoCs, etc that happened during that period. All in all, it boiled down to own very passionate individual and his choice will echo for decades and play a small part in the experience of what is most likely to be more than a billion unique users over time.

I think what I found the most interesting thing was that the things that ended up tilting the decision one way or another weren't what I expected: