Tech

Cloudflare reclaims 100TB of RAM through algorithmic overhaul

The web infrastructure giant has slashed the memory footprint of its Pingora Backend Router by more than 100TB globally, leveraging statistical analysis and a more compact data structure in Rust to optimise load balancing.

Editorial persona
Owen Mercer
Markets and Finance Editor
Published
Draft
Source: Hacker News · View original source
Tech
No image available
Markets & Finance

Cloudflare has reduced the memory footprint of its Pingora Backend Router service by more than 100TB of RAM globally, marking a significant efficiency gain for the web infrastructure company. The optimisation, detailed in a recent engineering post, involved adjusting the consistent hashing algorithm used for load balancing. By decreasing the number of hashes generated per server by 90% and implementing a more compact data structure in Rust, the company was able to reclaim substantial resources across its global network.

The move follows a previous effort by Cloudflare’s DNS team, which shed 100TB of memory last month. At Cloudflare’s scale, with thousands of servers, petabytes of RAM, and millions of CPU cores, even small percentage improvements yield significant resource savings. The company noted that maintaining equitable resource sharing between teams is complex, and these optimisations are critical to ensuring that every service can run on every node without wasted space.

The core of the issue lay in the pingora-ketama library, Cloudflare’s open-source solution for handling consistent hashing. The previous implementation used a default of 160 hashes per server, a standard inherited from NGINX, which resulted in high memory usage. Statistical analysis confirmed that the reduced hash count maintained acceptable error margins, validating the decision to lower the count. This mathematical approach allowed the company to balance workload distribution effectively while reducing the computational overhead associated with maintaining large hash rings.

In addition to the algorithmic changes, a structural improvement in the Rust implementation improved memory efficiency by 25%. By addressing Rust’s alignment rules, which require the size of a structure in memory to be a multiple of its largest field, engineers stored the hash and index as a raw byte array. This change, while technically straightforward, resulted in a significant reduction in the memory used for consistent hashing, demonstrating how low-level programming decisions can have macro-level impacts on resource consumption.

The update was rolled out gradually to manage cache invalidation and ensure network stability. Changing the hash ring alters where cacheable requests are routed, and a single global flip would have invalidated almost all cached content, leading to a spike in origin traffic. Instead, Cloudflare used a layered migration strategy, allowing the old and new ring versions to operate simultaneously. This approach provided a clean rollback path and allowed the company to monitor backend-selection traces, connection errors, and origin traffic closely during the transition.

The changes are now available in the pingora-ketama crate as an unadvertised cargo feature, allowing for simultaneous operation of old and new ring versions. For investors and institutions, the story underscores the value of engineering efficiency in capital-intensive tech sectors, where algorithmic precision can translate directly into reduced infrastructure costs and improved scalability.

Continue reading

More from Tech

Read next: Sony and UMG sue Suno over alleged copyright infringement in new AI models
Read next: Clicks Communicator shipments to start in December as price rises to $649
Read next: OpenAI and Microsoft warned of web ‘doom loop’ in internal files