BeCuriouzLearn something new every day
Discord's mysterious latency spike every 2 minutes
💡 At scale, the biggest performance problem can be your language runtime's automatic behavior — not your own code.
Discord's engineers had a service called Read States — it tracks which messages you've read in every channel. Written in Go, it kept hitting latency and CPU spikes on a strict schedule: every 2 minutes, like clockwork. Even after they optimized their code to allocate almost no memory, the spikes refused to go away.
The culprit was Go's garbage collector. Go's runtime forces a garbage collection at least every 2 minutes if one hasn't happened naturally. To decide what memory is still in use, the collector has to scan the whole live heap — and Read States held a giant in-memory LRU cache. So even with zero new garbage to clean up, the GC still walked millions of cached objects, stalling the service each time.
Rather than keep fighting the runtime, Discord rewrote the service in Rust, which has no garbage collector — memory is freed deterministically as values go out of scope. The rewrite erased the periodic spikes entirely, and the untuned Rust version outperformed the carefully-tuned Go version on latency, CPU, and memory across the board.
The lesson isn't 'Go is bad.' It's that a managed runtime's automatic behavior can become the bottleneck at scale — and no amount of application-level tuning fixes a cost baked into the runtime itself.