---
title: "Saving another 100TB of RAM with math (and Rust)"
description: "Cloudflare describes how excessive memory use in pingora-ketama, the consistent-hashing component of its Pingora Backend Router, was investigated as a resource-efficiency problem at global scale. Consistent hashing maps servers and cache keys onto a circular hash space, but a single hash per server creates uneven ranges, while multiple hashes improve balance; with 160 points per server, the coefficient of variation falls to about 8% in the 100-server example. The work produced a v2 ring with compacted storage, faster sorting, and a configurable base number of hashes per node, while retaining the existing v1 ring and supporting simultaneous use during migration. After the old ring was decommissioned, measured memory usage for PBR fell by 100TB globally, and the changes are available in pingora-ketama behind an unadvertised Cargo feature."
---

# Saving another 100TB of RAM with math (and Rust)

[Cloudflare](https://yomu.fyi/company/cloudflare) · Ivan Babrou · Sep 18, 2026

**Type:** Explainer

## Summary

Cloudflare describes how excessive memory use in pingora-ketama, the consistent-hashing component of its Pingora Backend Router, was investigated as a resource-efficiency problem at global scale. Consistent hashing maps servers and cache keys onto a circular hash space, but a single hash per server creates uneven ranges, while multiple hashes improve balance; with 160 points per server, the coefficient of variation falls to about 8% in the 100-server example. The work produced a v2 ring with compacted storage, faster sorting, and a configurable base number of hashes per node, while retaining the existing v1 ring and supporting simultaneous use during migration. After the old ring was decommissioned, measured memory usage for PBR fell by 100TB globally, and the changes are available in pingora-ketama behind an unadvertised Cargo feature.

## Context

Pingora Backend Router routes cacheable requests to servers by URL so that a data center can keep one copy of a file. Its consistent-hashing structures used more memory than expected, making them a target for optimization in a fleet with petabytes of RAM and millions of CPU cores.

## Approach / What changed

The v2 ring uses a compacted storage format, a faster sorting method, and a configurable base number of hashes per node. The existing v1 ring remains unchanged, and both versions can run simultaneously with the choice made per request, allowing a controlled migration before the old ring was removed.

## Takeaways

- With 100 servers and one hash per server, the coefficient of variation is approximately 99%; using 160 points per server reduces it to about 8%.
- The v1 and v2 rings can run at the same time, with the library selecting which ring to use on a request-by-request basis during migration.
- The optimized implementation is available in the pingora-ketama crate through an unadvertised Cargo feature.

## FAQ

### Why do multiple hashes per server improve workload balance?

Each server’s assigned range is the sum of multiple hash segments. Longer and shorter segments can offset one another, so the combined range becomes more even as the number of hashes increases.

### How was the ring change migrated without replacing the old implementation immediately?

The unchanged v1 ring and new v2 ring were run simultaneously, with the choice controlled per request. After migration reached 100%, the temporary path for the old ring was removed.

### What memory reduction did the optimization achieve?

After the version using the large, unused hash rings was decommissioned, measured memory usage for Pingora Backend Router dropped by 100TB globally.

**Tags:** [Optimization](https://yomu.fyi/topic/optimization), [Performance](https://yomu.fyi/topic/performance), [Rust](https://yomu.fyi/topic/rust)

- Source: [Cloudflare](https://blog.cloudflare.com/saving-100-tb-of-ram-with-math)
- Source URL: https://blog.cloudflare.com/saving-100-tb-of-ram-with-math
- Ingested by Yomu: 2026-09-18T18:00:13.063Z

[Read original post](https://blog.cloudflare.com/saving-100-tb-of-ram-with-math)
