Cloudflare Reclaims Another 100 Terabytes of RAM by Shrinking Its Consistent-Hashing Ring
Cloudflare cut hash points per server by 90% and shrank its hash-point struct by 25%, freeing over 100TB of RAM on its Pingora Backend Router.
Overview
Cloudflare has freed more than 100 terabytes of RAM across its global network by rewriting how one of its core routing services distributes cacheable requests, according to a Cloudflare Blog post published by engineers Kevin Guthrie and Mariia Iurchenko. The savings came from reworking the consistent-hashing scheme used by the Pingora Backend Router (PBR), the service that decides which server handles a given cacheable request.
The post frames the win against a separate effort from weeks earlier: Cloudflare’s DNS team had already shed roughly 100 terabytes of memory by redesigning how the 1.1.1.1 resolver’s in-memory cache stores its more than 250 billion entries, cutting the per-entry footprint by over 50%. The new PBR work is described as reclaiming “more than 100TB of RAM globally, on top of the 100TB of memory the DNS team was able to shed last month.”
What We Know
- PBR relies on pingora-ketama, Cloudflare’s open-source consistent-hashing library, to route cacheable requests to servers by URL so that only one copy of a file needs to be stored per data center, according to the Cloudflare Blog.
- Consistent hashing works by generating multiple hash points per server rather than just one, because a single point per server leaves load badly imbalanced; the post’s illustrative 100-server example shows the coefficient of variation dropping from roughly 99% to about 8% once each server gets 160 hash points instead of one, according to the Cloudflare Blog.
- That figure of 160 points per server is not arbitrary: it is the same default NGINX and Pingora both hard-code, and Cloudflare’s engineers note that with a weighting factor of 625, the math works out to 160×625 = 100,000 hash points generated per server before the change, according to the Cloudflare Blog.
- Engineers found steeply diminishing returns in that volume of hash points — the post states that “the last 90,000 hashes we added are buying us a minuscule 0.7% reduction in error” — and concluded the number of hashes generated per server could be cut by 90% “without incurring any appreciable error,” according to the Cloudflare Blog.
- Separately, the team shrank the memory footprint of each remaining hash point itself. The original struct stored a 32-bit hash alongside a 32-bit server index; since PBR is never expected to coordinate more than roughly 65,000 servers, the index field was narrowed to 16 bits, a change the post says “reduces the amount of memory used for consistent hashing by a whopping 25%,” according to the Cloudflare Blog.
- The two changes compound: fewer hash points, and a smaller footprint for each one that remains.
- The rollout ran both hashing schemes side by side rather than switching all at once: “PBR carried both versions of the cacheable load balancer in memory: the old ketama ring and the new smaller one,” starting in small validation locations before expanding to “progressively larger groups of data centers” and eventually the rest of the network, according to the Cloudflare Blog.
- During that staged rollout, engineers watched “backend-selection traces, ring-version counters, PBR connection errors, process memory, startup time, cache behavior, and origin traffic” before decommissioning the older, larger hash rings for good, at which point fleet-wide memory usage dropped by the full 100TB, according to the Cloudflare Blog.
- Pingora-ketama itself is described in the post as “a (for now) unadvertised cargo feature” of Cloudflare’s broader open-source Pingora framework, the Rust-based proxy library the company open-sourced in 2024 and has since built into replacement infrastructure for its retired NGINX stack.
What We Don’t Know
The post does not name the specific data centers used for initial validation, disclose how many servers or data centers were involved at each stage of the rollout, or give an exact calendar date for when the old hash rings were fully decommissioned. Cloudflare also has not said whether the same hash-point reduction and struct-shrinking techniques will be applied to other consistent-hashing uses elsewhere in its infrastructure.
Analysis
The post is notable less for the raw total — 100TB sounds large in isolation but is a small fraction of Cloudflare’s stated “petabytes of RAM” fleet-wide, per the Cloudflare Blog — and more for the method: a statistical argument (diminishing error reduction from additional hash points) paired with a low-level Rust struct optimization (shrinking an integer field), applied at a scale where, as the earlier DNS cache post put it, “wasting a single byte per entry costs more than 250 gigabytes of memory across our fleet.” Combined with the DNS team’s separate 100TB reduction weeks earlier, the two posts together describe roughly 200TB of fleet-wide memory reclaimed within about a month through unrelated optimizations to different services, illustrating how much headroom remains in mature, widely-used infrastructure code even after years in production.