hasina.dev
EN
menu
← All posts

You (most likely) don't need to migrate to Rust

9 min read

Illustration of a developer drawing a diagram on a whiteboard: a Node.js program, V8, libuv and the operating system

I actually felt a bit uncomfortable putting "you" in the title, as I designed this blog primarily to share what I'm doing, not to tell anybody what to do. But today is my birthday! And what better way to celebrate it than complaining about my industry and where it's headed!? So I hope you'll give me a pass this time.

You may remember that a few months ago, Bun's author decided to rewrite Bun from Zig to Rust. It feels like 2 years ago, yet it was only in July. Crazy things happened this year!

The migration took the internet by storm, and many people and companies followed the same path: Google is massively migrating major C and C++ codebases to Rust11 the Google article I'm pointing to is mostly about their new AI, Argon, but they mention the rewrite inside. and GitHub moved the GitHub Copilot runtime from TypeScript to Rust, "using Copilot".

A revolution in the industry

I believe this is a once-in-a-decade shift for the tech industry.22 AI being once in a century, if not in history! It's like the React movement of the 2010s, and just like the React movement, it gives the feeling that it's the standard now. And just like the React movement, I feel like it may be blown out of proportion for the wrong reasons. Whether or not smaller companies are actually doing it, I don't know yet, but it's much talked about in the dev community.

React: the revolution of the 2010s

Do I hate React? Well, that's a difficult question! I'm a React dev and also a Vue dev on the front end. What I can say is that I wish Vue had become the standard for the front-end industry.33 People talk about Svelte being the king, the best, the GOAT, but I honestly never touched it enough to form an opinion, so we'll stick with Vue.

This perspective is neither particularly fringe nor subjective. Let me show you with just one thing: mutation. Here's an example in Vue:

<script setup>
	import { ref } from "vue";

	const items = ref(["apple"]);

	function add() {
		items.value.push("banana");
	}
</script>
<template>
	<button @click="add">{{ items.join(" ") }}</button>
</template>

This is valid Vue code. You declare an array of items and put it in a ref. Then, if you want to add an item to it, you do what any sane person does: you push the element into it. Okay, we have the .value here, but hey, that's because it's a ref. The mental load is basically nothing.

Now let's try the same thing with React:

import { useState } from "react";

function List() {
	const [items, setItems] = useState(["apple"]);

	function add() {
		items.push("banana"); // nope!
		setItems(items); // no no!
	}

	return <button onClick={add}>{items.join(" ")}</button>;
}

You would think this should work: you had the array, you pushed into it and you set the items. But no! Because of how mutation works. Vue wraps your data in a reactive proxy through ref and watches every change. React, on the other hand, still sees the same array after a push, because it's the same reference. React only "reacts" when you set a completely new array, like this:

import { useState } from "react";

function List() {
	const [items, setItems] = useState(["apple"]);

	function add() {
		setItems([...items, "banana"]); // a new array is how it works!
	}

	return <button onClick={add}>{items.join(" ")}</button>;
}

I mean, it's fine! That's how JavaScript really works anyway, but jeez, if the engine can do it for you, why do it yourself? It adds cognitive load. You can learn Vue in one hour and develop the intuition along the way. With React, you'll need to bang your head against the wall for an afternoon before it flows naturally. And this example is just the tip of the iceberg. I could talk about re-rendering too, but we're already deviating too much!

So why is React so popular when Vue is better? Because, that's why!

React is popular not really because it came first, but because it was the "tool of the cool kids". Every library that came out was React-first. Blogs were written about React. Vue had an edge for a while, but it quickly got overshadowed by React because of propaganda.44 I'm totally aware that there's more to it than propaganda, like framework fatigue: devs who built libraries built them with the framework they already knew, which started a cycle of reinforcement for React that also affected the job market as a whole. But it's my birthday, so I'll leave out the nuance this once. I'm tired!

Buy with emotion, justify with logic

At some point, it became clear to me! Devs are just like regular people. Just as people buy with emotion and justify with logic, we make our tech decisions not out of pure rational thought but because they feel like the right thing: if Big Tech did it, why shouldn't I? That's how we end up with microservices for an app that barely has any features, or a complex, badly implemented hexagonal architecture where we should have just gone with the default framework setup. People bigger than us paved the way, we read that article on the Netflix engineering blog, and we told ourselves we should bring it into our own project.

So what about Rust, then? You want to move to Rust for fewer bugs? Well, let's take a closer look.

Bun migrated from Zig to Rust, with Jarred, the creator of Bun, explaining that they ran into memory safety issues and resource bugs in the runtime's native layer. Then Andrew, the creator of Zig, wrote a pointed response against him about it. Andrew's words seem filled with anger and frustration, but even if we should take his account with a grain of salt, I think it rings true to some extent. I mean, Jarred really seems like the kind of guy who is on the "pragmatic" side of things rather than the "crafter" side. So basically, even if he could have done a "better job" with Zig,55 who am I kidding, talking down on Jarred in any way? I could spend 3 or 4 reincarnations and still not be half the man he is in terms of technical skills. he took the other route and just used Anthropic's unlimited tokens to port the project to Rust, so he wouldn't have to worry so much about memory issues anymore.

Google is Google, and for them it actually made sense. I don't know much about the details, but Microsoft, which operates at the same scale, reported that 70% of the vulnerabilities they assign a CVE to each year are memory safety issues.

GitHub Copilot's migration was the most interesting one. Most people assume Rust is best for LLMs because of what its compiler catches. But as their team actually found out, 84% of the errors it caught were, and I quote, "bread-and-butter static typing, and a C# or Java or Go compiler would catch all of them just as well, [...] If this is the argument for pointing agents at Rust, it’s really an argument for pointing them at any statically typed language." They said this because ownership, borrowing and lifetime errors combined were only 1.7%.

Excerpt from the GitHub blog: of 8,678 rustc errors, 37% were name and import resolution, 22% missing methods or fields, 14% type mismatches and 11% unsatisfied trait bounds
the actual breakdown of the errors caught by Rust's compiler

But here's the thing about memory: Rust's memory safety protects you from the nasty stuff like use-after-free, double frees and buffer overflows. And guess what? If you write TypeScript, Ruby or Python, the garbage collector already took care of all that for you. You already have memory safety! That's exactly why Bun and Google make sense: Zig, C and C++ don't have that safety net. Your Node.js app does.

So what's left for us web devs? Leaks, mostly. And plot twist: Rust doesn't save you from leaks either. Leaking memory is perfectly "safe" in Rust's eyes!

From personal experience: on my assignment at L'Équipe, we moved the website from Vue/Nuxt to Node.js and Vue with TypeScript. We've had two memory issues with the new architecture in the last 10 months, and we may never run into one again as the architecture matures. I'm not saying it's nothing, but a Rust rewrite would not have been the answer. Understanding how our app holds on to memory was.

But what about Rust's performance?

I know, right? It's the main reason most people want to move to Rust. But I deliberately saved it for last. So here it is: before moving anything to anything for performance reasons, I think we need to ask ourselves whether we've already optimized everything we can with the tech we have. Sometimes we can improve performance just by making the most of our stack. That's what we did at L'Équipe. Yes, we got rid of Nuxt and went back to basics, but much of the code just had to be translated from Vue 2 to Vue 3, and that was the fastest process we could think of. If something broke, we'd know it and know what to do, because we already mastered the language. It wasn't just about prompting the AI (well, we did that a lot): we knew how things worked from first principles. If your team doesn't know Rust at all, you may not make the best decisions at every turn.

I read an article on X's engineering blog. As they state, X.com is the 6th most visited website in the world. Yet they had performance issues. What did they do? Migrate to Rust? No. Well, mostly not. They went down the rabbit hole, identified the issue in the architecture, and laid out a plan. The app that used to run on 3 servers now runs on one. And they built it with Vite, React, Node.js/Fastify and TypeScript. Rust did play a small part in the link-preview card image generator, but the app itself is Node.js.

I'm convinced that most of us can do more with what we have if we're really serious about it. That's why I like the Ruby community. Look at how Shopify and GitHub, as big as they are, still run Ruby on Rails under the hood, and blog about it! Shopify's Rails app handles ridiculously large traffic on Black Friday without cracking, even though Ruby is notorious for being among the slowest programming languages out there, comparable to Python. This is actually one of the reasons why I still stick with Ruby on Rails, even though I don't use it professionally anymore due to low demand in the Paris job market.

Maybe it's just my philosophy and personality, but I find joy in thinking I've pushed a language to its full potential. And if you can do so much with less, you can do even more than anyone when you have plenty.

Outro

Well, I think I gave too many sermons for a birthday. But I hope we got this cleared up! You may still want to move your platform to Rust, though. Go ahead and do it! Don't let some random guy on the internet tell you what to do ;) My concern is really about stable, established projects. If you're starting a new project, it's fine to explore a bit.

Anyway, that's all I've got for today. See you in a month! I already have something to talk about.

Notes

  1. the Google article I'm pointing to is mostly about their new AI, Argon, but they mention the rewrite inside.

    ↩
  2. AI being once in a century, if not in history!

    ↩
  3. People talk about Svelte being the king, the best, the GOAT, but I honestly never touched it enough to form an opinion, so we'll stick with Vue.

    ↩
  4. I'm totally aware that there's more to it than propaganda, like framework fatigue: devs who built libraries built them with the framework they already knew, which started a cycle of reinforcement for React that also affected the job market as a whole. But it's my birthday, so I'll leave out the nuance this once. I'm tired!

    ↩
  5. who am I kidding, talking down on Jarred in any way? I could spend 3 or 4 reincarnations and still not be half the man he is in terms of technical skills.

    ↩

Did this post speak to you?