Cloudflare freed 100TB of RAM with math, not hardware

More than 100 terabytes of RAM returned to Cloudflare's global fleet, without buying a single server. On September 18, the performance team told the story of a routine ticket about abnormal memory usage that turned into a fleet-wide optimization. The story matters less for the headline number than for the method: profile, understand the algorithm, then fix how the data is represented before thinking about hardware.
Where it started: a router drinking too much
It began with a ticket filed by Ivan Babrou: the Pingora Backend Router (PBR), Cloudflare's internal load-balancing service, was using far more memory than expected. The culprit was pingora-ketama, their open-source consistent hashing library, which kept structures tied to dozens of hash rings — up to 6 GB in some cases.
Consistent hashing in one minute
Consistent hashing distributes requests across servers in a stable way: adding or removing a node only reshuffles a fraction of the traffic. At Cloudflare, PBR uses it to route cacheable requests to the server already holding the file, so only one copy exists per data center.
The classic problem: hashing is essentially random, so the ranges assigned to each server are uneven. With 100 servers and a single hash per server, the coefficient of variation approaches 99% — some servers would handle twice the expected load while others sit nearly idle. The canonical answer, borrowed from NGINX, is to generate 160 hash points per server, which brings the error down to roughly 8%.
Why it balloons in memory
160 points is only the baseline. Then comes weighting: at Cloudflare, a server's weight is proportional to its disk space, so some servers carry far more than 160 points. Above all, not every server can serve every request — compliance constraints and enabled caching features mean each feature combination needs its own ring. A handful of options is enough to end up with dozens of rings, all in memory.
Two fixes, zero new hardware
The first fix is purely structural: the Point struct storing each ring entry took 8 bytes (a u32 for the hash, a u32 for the server index). PBR never coordinates more than 65,000 servers at once, so a 16-bit index is enough. Rust's memory alignment rules prevent simply changing the field's type, so the team stored hash and index in a raw 6-byte array with getters. Result: 25% less memory for consistent hashing, without touching a line of routing logic.
The second fix is mathematical: by deriving the exact formula for the coefficient of variation with k hashes per server, the team showed that each order-of-magnitude gain in accuracy costs almost an order of magnitude more points. Worse, past a certain threshold, collisions on 32-bit hashes (the birthday paradox) actually degrade the real distribution. The bottom line: 90% of the hash points generated per server could be dropped with no measurable degradation in balancing.
Add the two together: more than 100TB of RAM reclaimed across the fleet.
The DNS cache precedent
It wasn't a first. On September 8, the same team published a DNS cache optimization that cut memory per entry by 56%, also freeing roughly 100TB. Two 100TB wins in ten days, purely by revisiting how data structures are represented.
What it means for your infrastructure
The takeaway is not "do the same thing" but "profile before you scale." A library that has run for years can hide massive savings, provided you measure: a single ticket about abnormal memory usage kicked all of this off, not a purchasing decision.
Keep a sense of proportion, too. At Cloudflare's scale, 100TB is a meaningful fraction of a petabyte-class fleet. On a twenty-node cluster, the same kind of fix amounts to gigabytes — useful, but not a hardware budget saved. The transferable lesson is the method: data representation first, capacity second.