# Discord Go to Rust: The Read States Rewrite | gen2.dev

> Discord rewrote one service, Read States, from Go to Rust to end latency spikes caused by garbage collection. What it measured, and how it cut over.

Source: https://gen2.dev/cases/discord-go-to-rust/

---

Case file 35

# Discord's Read States: one service rewritten from Go to Rust

Discord's Read States service was fast, except every two minutes. The cause was the Go garbage collector, and tuning did not remove it. Discord rewrote that one service in Rust, tested it against the Go version, tried it on a single node and then moved the whole fleet. The spikes ended.

![Slide: a Go service with a latency spike every two minutes, rewritten in Rust and rolled out from one canary node to the fleet, and steady response times afterward.](https://gen2.dev/img/case-discord-go-to-rust.png)

Most rewrites in these files replace a product. This one replaced a single back-end service that no user could name, and it is the clearest example here of a rewrite with a small scope and a number to beat.

The account of the work rests on one source: the post Discord published in February 2020, written by Jesse Howarth, a Discord infrastructure engineer. The trade press reported it from that post the same week.

## Gen 1

The service is called Read States. In Howarth's words, "Its sole purpose is to keep track of which channels and messages you have read." That makes it small in purpose and very large in traffic. It is accessed every time a user connects, every time a message is sent and every time a message is read. "In short, Read States is in the hot path."

The post gives the scale without exact totals:

-   "Discord has billions of Read States."
-   "There is one Read State per User per Channel."
-   "There are hundreds of thousands of cache updates per second."
-   "There are tens of thousands of database writes per second."

To keep that fast, each Read States server holds a Least Recently Used cache in memory, with millions of users in each cache. The service was written in Go.

It mostly worked. "It was fast most of the time, but every few minutes we saw large latency spikes that were bad for user experience."

## The decision

The team first found the cause, and that is what made the later decision defensible. The spikes came from garbage collection. Go, the post says, "will force a garbage collection run every 2 minutes at minimum," whether or not memory has grown. On each run, "the garbage collector needed to scan the entire LRU cache." Then the team tried to fix it in Go.

-   **Tuning the collector** did not help.
-   **Shrinking the cache** gave the collector less to scan and made the spikes smaller. It also sent more requests to the database, which "resulted in higher 99th latency times."
-   **Upgrading Go** was tried as well. A footnote records: "We tried versions 1.8, 1.9, and 1.10 without any improvement."

With those options used up, the remaining choice was a language with no collector. Rust was already in use elsewhere at Discord, and the post states the reasoning in one sentence: "Rust does not have garbage collection, so we figured it would not have the same latency spikes Go had." Rust frees memory as soon as the program is done with it, so an entry evicted from the cache is gone at once and there is nothing to scan later.

There was a known risk. The asynchronous features the service needed were available only in Rust's unstable nightly builds at the time. The team "committed to running on nightly until async was fully supported on stable."

## What happened

The post describes the port in a single sentence: "The actual rewrite was fairly straight forward."

The order of the steps is what makes this a useful case.

1.  **Load test against Gen 1.** The first result: "The latency of the Rust version was just as good as Go's and had no latency spikes!"
2.  **Optimize.** The team changed a data structure inside the cache to use less memory, swapped the metrics library and reduced memory copies. After that, "we were able to beat Go on every single performance metric."
3.  **Canary.** "We put it out to a single canary node, found a few edge cases that were missing, and fixed them."
4.  **Fleet.** "Soon after that we rolled it out to the entire fleet."

A footnote dates it: "The initial port from Go to Rust was completed in May 2019." The post does not say when the work started or how many people did it.

The results are given as graphs and a summary. "Latency, CPU, and memory were all better in the Rust version." The post points out that in the new graphs the average time is measured in microseconds.

With no collector to protect, the old trade-off reversed. After the service had run for a few days, the team raised the cache capacity to 8 million Read States, the opposite of what Go had forced. Later, an upgrade of the async runtime, tokio, to version 0.2 "gave us CPU benefits for free." The bet on nightly builds was settled too, when async support reached stable Rust. "The bet paid off."

## What made it work

-   **The cause was known before the rewrite was proposed.** The team could say exactly what Go was doing, how often and why. A rewrite aimed at "performance" in general has no test for success.
-   **The cheaper fixes were tried first.** Tuning, a smaller cache and three versions of Go all came before a new language. [Rewrite vs refactor](https://gen2.dev/guide/rewrite-vs-refactor/) covers the same choice.
-   **The scope was one service.** Read States had one job and a clear boundary, so the new version could stand in for the old one without touching anything else.
-   **Old and new were measured side by side.** The same load, the same metrics, both versions. The Go version being compared was not a weak one: the post calls it "hyper hand-tuned."
-   **Cutover was a canary and then the fleet.** The canary found the missing edge cases while only one node was exposed. [Cutover](https://gen2.dev/guide/cutover/) covers the options.
-   **The language was not a leap.** Discord had used Rust before: a May 2019 post describes using it to speed up its Elixir services. It kept choosing it afterward; a 2023 post on its message storage calls Rust "a language we've been using more and more at Discord."

## The verdict

It worked. The spikes that started the project are gone from the graphs, and every other measure the post reports improved.

Three cautions go with that. The only source is Discord's own post, and it gives graphs and summaries, not a table of figures. It gives no cost, no team size and no duration. And the title promises more than the post reports: one service was switched, and the post's own closing is careful about the rest. "To be clear, we don't think you should rewrite everything in rust just because." Discord, it says, uses Rust "where it makes sense."

## What to take from it

-   **Find the cause before choosing the cure.** "Go is slow" would not have justified this. "The collector scans the whole cache every two minutes" did.
-   **Spend the cheap options first, and write down that they failed.** That record is the argument for the rewrite.
-   **Rewrite the smallest thing that contains the problem.** One service can be replaced in months and compared directly. A platform cannot.
-   **Keep Gen 1 as the benchmark.** The new version shipped when it matched the old one under load, and not before.
-   **Do not generalize from one service.** The lesson Discord drew was to use the new language where it fits, not everywhere.

## Sources

1.  [Jesse Howarth - Why Discord is switching from Go to Rust (Discord blog, February 4, 2020)](https://discord.com/blog/why-discord-is-switching-from-go-to-rust) - Discord's own account, and the only account of the work itself: what the service does, the cause of the spikes, what was tried in Go, the rewrite, the rollout and the results
2.  [@IT - Discord changes an implementation language from Go to Rust (ITmedia, February 10, 2020, in Japanese)](https://atmarkit.itmedia.co.jp/ait/articles/2002/10/news038.html) - trade press report of the Read States rewrite, written from Discord's post the week it appeared
3.  [Matt Nowack - Using Rust to Scale Elixir for 11 Million Concurrent Users (Discord blog, May 17, 2019)](https://discord.com/blog/using-rust-to-scale-elixir-for-11-million-concurrent-users) - an earlier Discord project that used Rust
4.  [Bo Ingram - How Discord Stores Trillions of Messages (Discord blog, March 6, 2023)](https://discord.com/blog/how-discord-stores-trillions-of-messages) - Discord choosing Rust again, for its data services

Last updated November 28, 2026.

## Scorecard

Worked

Gen 1

The Read States service written in Go: an in-memory cache of read positions in front of a database, with latency spikes every two minutes

Gen 2

The same service rewritten in Rust, which has no garbage collector

Approach

Rewrite one small, self-contained service, load test it against the old version, try it on one canary node, then roll it out to the fleet

How long

Not stated; the initial port was completed in May 2019 and Discord published its account in February 2020

Verdict

A rewrite that worked because it was narrow. One service, one measured problem with a known cause, and a new version that could be compared with the old one number for number.

## More case files

-   [Netscape 6](https://gen2.dev/cases/netscape-6/)
-   [Python 2 to 3](https://gen2.dev/cases/python-2-to-3/)
-   [Firefox Quantum](https://gen2.dev/cases/firefox-quantum/)
-   [Perl 6 and Raku](https://gen2.dev/cases/perl-6-raku/)
-   [AngularJS to Angular](https://gen2.dev/cases/angularjs-to-angular/)
-   [Windows Longhorn](https://gen2.dev/cases/windows-longhorn/)
-   [Digg v4](https://gen2.dev/cases/digg-v4/)
-   [Twitter to the JVM](https://gen2.dev/cases/twitter-jvm/)
-   [Basecamp](https://gen2.dev/cases/basecamp/)
-   [IPv4 to IPv6](https://gen2.dev/cases/ipv6/)
-   [VB6 to VB.NET](https://gen2.dev/cases/vb6-to-vb-net/)
-   [HTTP/2 and HTTP/3](https://gen2.dev/cases/http-2-and-3/)
-   [K-12 browser rewrite](https://gen2.dev/cases/k12-browser-rewrite/)
-   [Mac OS X](https://gen2.dev/cases/mac-os-x/)
-   [Microsoft Edge](https://gen2.dev/cases/edge-chromium/)
-   [Winamp3](https://gen2.dev/cases/winamp3/)
-   [Slack desktop](https://gen2.dev/cases/slack-desktop/)
-   [Evernote 10](https://gen2.dev/cases/evernote/)
-   [Uber rider app](https://gen2.dev/cases/uber-rider-app/)
-   [HealthCare.gov](https://gen2.dev/cases/healthcare-gov/)
-   [Thunderbird Supernova](https://gen2.dev/cases/thunderbird-supernova/)
-   [Skype](https://gen2.dev/cases/skype-cloud/)
-   [Sonos app (2024)](https://gen2.dev/cases/sonos-app-2024/)
-   [FBI Virtual Case File](https://gen2.dev/cases/fbi-virtual-case-file/)
-   [LinkedIn Inversion](https://gen2.dev/cases/linkedin-project-inversion/)
-   [Netflix to AWS](https://gen2.dev/cases/netflix-cloud-migration/)
-   [TSB migration](https://gen2.dev/cases/tsb-migration/)
-   [Phoenix pay system](https://gen2.dev/cases/phoenix-pay/)
-   [Universal Credit](https://gen2.dev/cases/universal-credit/)
-   [Queensland Health payroll](https://gen2.dev/cases/queensland-health-payroll/)
-   [Facebook for iOS](https://gen2.dev/cases/facebook-native-ios/)
-   [New Microsoft Teams](https://gen2.dev/cases/microsoft-teams-2/)
-   [Dropbox to Python 3](https://gen2.dev/cases/dropbox-python-3/)
-   [Instagram to Python 3](https://gen2.dev/cases/instagram-python-3/)
-   [Reddit Redesign](https://gen2.dev/cases/reddit-redesign/)
-   [GetPranks](https://gen2.dev/cases/getpranks/)
-   [37signals cloud exit](https://gen2.dev/cases/37signals-cloud-exit/)
-   [IRS Individual Master File](https://gen2.dev/cases/irs-individual-master-file/)
-   [All case files](https://gen2.dev/cases/)
