Key Takeaways
- Packing each hash point into a 6-byte raw byte array instead of an 8-byte aligned struct cut consistent hashing memory by 25%.
- Closed-form error math revealed that the last 90,000 hash points per server bought only a 0.7% error reduction, so 90% of them were removed.
- Dual rings, per-request ring selection, and independently staged geographic rollout avoided cache collapse while preserving a clean rollback path.
Table of Contents
How a Six-Byte Struct Unlocked 100TB
Cloudflare’s Pingora Backend Router service has reclaimed more than 100TB of RAM worldwide by reworking the data structures behind its consistent hashing layer.
The savings came from two surgical moves: shrinking each hash point from eight bytes to six, then eliminating 90 percent of the hashes assigned to each server after a closed-form error analysis showed the extra points added almost no load-balancing value.
That reduction stacks on top of another 100TB memory win from Cloudflare’s DNS team, doubling a massive infrastructure efficiency gain at a company running thousands of servers and petabytes of RAM.
Why Consistent Hashing Became the Memory Hotspot
Consistent hashing lets Cloudflare route cacheable requests to servers by URL without relocating every file when a server joins or leaves.
Each server and each task maps onto a hash-based number line, and a task is assigned to the first server to its left, wrapping around at the boundary.
With a single hash per server, the distribution can be extremely uneven. In a 100-server example, the coefficient of variation is roughly 99 percent, meaning some nodes can handle nearly twice the ideal load while others sit almost idle.
Adding multiple hash points per server smooths the assignment. NGINX hardcodes 160 points per server, and Pingora used the same default, dropping the coefficient of variation from about 99 percent to roughly 8 percent in that same 100-server model.
Cloudflare also uses ketama-style weights so storage-heavy servers receive proportionally more traffic, which scales hash counts by disk capacity. Feature combinations multiply into dozens of separate rings, and those rings all reside in memory.
In some cases, the resulting structures consumed 6GB per process, which triggered the original ticket about excessive memory in pingora-ketama.
The Math That Justified a 90% Reduction
The first storage win targeted the Point struct. It originally paired a 32-bit hash with a 32-bit server index, consuming eight bytes in memory.
Since Pingora Backend Router will never coordinate more than roughly 65,000 servers at once, the index could safely drop to 16 bits.
Rust’s alignment rules prevented a simple six-byte struct, so the team stored the hash and index in a raw byte array and added getter methods to reconstruct the fields.
That change alone cut consistent hashing memory by 25 percent.
The deeper win came from questioning the hash count itself. The engineering team derived the exact coefficient of variation for k hashes per server instead of relying on approximations.
With a weight factor of 625, each server ended up with 100,000 hash points. The math showed that the final 90,000 points were buying only a 0.7 percent reduction in error margin.
Collisions in 32-bit hash space made the argument stronger. Simulated results for 2,048-server data centers showed error increasing as hash counts climbed between 10,000 and 100,000 per server.
That behavior reversed the usual assumption: fewer hashes could preserve distribution quality while freeing massive memory. The team cut hash counts by 90 percent.
A Staged Migration That Avoided Cache Collapse
Changing hash rings changes where cacheable requests land, so a global cutover would have invalidated nearly all cached content and triggered a surge in origin traffic.
Pingora Backend Router carried both the old ketama ring and the new smaller ring in memory during migration. Each request used the migration framework to choose a ring, keeping decisions stable per request hash and preserving a clean rollback path.
The rollout proceeded in layers, starting with small validation locations and expanding through progressively larger data center groups.
Traffic percentage and geographic scope were controlled independently, which kept cache churn from spreading everywhere at once.
Observability focused on backend-selection traces, ring-version counters, connection errors, process memory, startup time, cache behavior, and origin traffic. After reaching 100 percent migration, the team removed the legacy ring path and confirmed the 100TB memory drop.
The changes are now available in the pingora-ketama crate as an unadvertised cargo feature. The v2 ring includes compacted storage, faster sorting, and scalable base hash counts, while v1 remains identical so both can run side by side on a request-by-request basis.
What High-Scale Teams Should Recompute Next
The 100TB result shows how a small alignment-aware data change can compound across thousands of nodes when the underlying structure is repeated millions of times.
For performance teams, the larger lesson is the negative result: 90 percent of the hash points were not improving load distribution in any meaningful way.
That insight emerged only because the team replaced rules of thumb with exact probability formulas and collision-aware simulations.
The migration pattern adds another lesson. Running dual rings and controlling traffic geography independently turned a risky cache invalidation event into a reversible operational change.
The result is a 100TB memory reduction that did not sacrifice cache stability or traffic distribution.
For infrastructure teams turning algorithmic efficiency into production memory savings, Andres SEO Expert’s WordPress Speed Engineering service brings the same measurement-first approach — contact the team.
Frequently Asked Questions
How did Cloudflare save 100TB of RAM with consistent hashing?
Cloudflare reclaimed over 100TB of RAM by optimizing the consistent hashing layer in its Pingora Backend Router. The team shrank each hash point from eight bytes to six and then eliminated 90% of the hashes assigned to each server after a closed-form error analysis showed the extra points added almost no load-balancing value.
Why did Cloudflare shrink the Point struct from 8 bytes to 6 bytes?
The original Point struct stored a 32-bit hash and a 32-bit server index, using 8 bytes. Since Pingora Backend Router never needs more than roughly 65,000 servers, the index could be reduced to 16 bits. Rust alignment prevented a simple 6-byte struct, so the team used a raw byte array with getter methods. This cut consistent hashing memory by 25%.
Why did Cloudflare reduce hash points per server by 90%?
With a weight factor of 625, each server had 100,000 hash points. Exact probability formulas showed the final 90,000 points only reduced error margin by 0.7%. Collision-aware simulations also showed error increasing as hash counts climbed between 10,000 and 100,000 per server. Fewer hashes preserved distribution quality while saving memory.
How did Cloudflare avoid cache collapse during the hash ring migration?
Pingora Backend Router kept both the old ketama ring and the new smaller ring in memory. Each request used a migration framework to select a ring, keeping decisions stable per request hash and allowing clean rollback. The rollout started with small validation locations and expanded through larger data center groups, controlling traffic percentage and geography independently.
What is consistent hashing and why use multiple hash points per server?
Consistent hashing maps servers and tasks onto a hash-based number line, assigning each task to the first server to its left. A single hash per server can be very uneven; in a 100-server example, the coefficient of variation is about 99%. Adding multiple hash points per server smooths distribution, dropping the coefficient of variation to roughly 8% with 160 points per server.
What is pingora-ketama v2 and how does it differ from v1?
The pingora-ketama crate now offers a v2 ring as an unadvertised cargo feature. V2 includes compacted storage, faster sorting, and scalable base hash counts. V1 remains identical so both rings can run side by side on a request-by-request basis during migration. This allowed Cloudflare to reach 100% migration and then remove the legacy ring path.
What can high-scale teams learn from Cloudflare’s Pingora memory optimization?
The main lesson is to replace rules of thumb with exact probability formulas and collision-aware simulations. Cloudflare found that 90% of hash points were not meaningfully improving load distribution. Another lesson is the migration pattern: dual rings with independent traffic and geographic controls turned a risky cache invalidation into a reversible operational change.
