How Cloudflare Saved Another 100TB of RAM with Math: Probabilistic Data Structures in Practice

Cloudflare saved 100TB of RAM by replacing exact storage with probabilistic data structures like Bloom Filters and HyperLogLog.
Cloudflare published a technical blog explaining how they saved another 100TB of memory through mathematical and algorithmic optimization rather than adding hardware. The core insight is that in hyperscale infrastructure, many use cases don't require 100% precision. By adopting probabilistic data structures — Bloom Filters, HyperLogLog, Count-Min Sketch — memory footprint can be reduced by orders of magnitude at the cost of controllable, quantifiable error. The real engineering challenges lie in managing error rates at scale, maintaining consistency in distributed environments, and migrating smoothly from exact to approximate implementations.
Introduction: Replacing Hardware with Math
A recent Cloudflare engineering blog post titled Saving Another 100TB of RAM with Math sparked lively discussion on Hacker News (275 upvotes, 57 comments). The word "another" in the title is telling — this isn't the first time Cloudflare has achieved massive memory savings through algorithmic optimization rather than hardware investment. For an edge computing company operating hundreds of data centers worldwide and handling enormous traffic volumes, every gigabyte saved per server, multiplied across a massive fleet, translates into meaningful cost and energy savings.
This article draws on the publicly available blog post and community discussion. The core idea is consistent throughout: rather than brute-forcing the problem by adding more physical memory, rethink it from the perspective of data structures and mathematical modeling — and store and query data in smarter ways.

Why Memory Optimization Matters So Much to Cloudflare
In hyperscale infrastructure, memory is often scarcer and more expensive than CPU. Edge nodes need to cache large amounts of metadata in memory — routing information, access control lists, rate-limiting counters, cache indexes, and more. If these data structures are implemented in the most straightforward way (such as storing every key exactly in a hash table), memory consumption balloons to unmanageable levels once the data reaches the billions scale.
What does 100TB of memory mean for a company like Cloudflare? It's roughly equivalent to the combined memory of thousands of servers. The freed-up capacity can support more workloads while directly reducing ongoing costs for hardware procurement, rack space, and power and cooling. This is the business logic behind "saving memory with math": algorithmic optimization requires a one-time investment but delivers compounding long-term returns.
The Core Approach: Probabilistic Data Structures and the Precision-Space Trade-off
This class of memory optimization typically centers on probabilistic data structures. The underlying philosophy is simple: in many real-world business scenarios, you don't need a 100% precise answer — you just need an approximation within a controllable margin of error. Trading a small amount of precision for an order-of-magnitude reduction in space is an excellent deal.
The Common Technical Tools
In engineering practice, the most commonly used tools for this kind of optimization include:
- Bloom Filter / Cuckoo Filter: Used to determine whether an element "might exist," providing set membership queries at extremely low space cost while allowing a tunable false positive rate.
- HyperLogLog: Used for cardinality estimation (distinct count), capable of estimating billions of unique elements using just a few kilobytes of memory.
- Count-Min Sketch: Used for frequency estimation — highly practical in traffic analytics and hot-spot detection.
What these structures share is that memory usage doesn't grow linearly with data volume. Instead, it's compressed to a fixed or slowly growing footprint, at the cost of quantifiable, controllable error. For use cases like routing, rate limiting, and caching that tolerate small errors, this trade-off is essentially a free lunch.
It's worth unpacking how a Bloom Filter works: it uses a bit array and several hash functions. When inserting an element, it sets multiple bit positions to 1; when querying, it checks whether all corresponding bits are 1. This design means it can only produce false positives (incorrectly reporting that an element exists) — never false negatives (missing an element that actually exists). That asymmetry is critical in scenarios like cache penetration prevention. The Cuckoo Filter is an improved variant that supports deletions and achieves better space efficiency at the same false positive rate. Its name comes from the cuckoo hashing collision resolution strategy — when a slot is occupied, the existing element gets "kicked out" and relocated to an alternate position, much like a cuckoo pushing other eggs out of a nest. HyperLogLog is based on a statistical insight: after uniform hashing, the maximum number of leading zeros has a logarithmic relationship with the set's cardinality. This allows a handful of registers to estimate the count of vast numbers of unique elements — Redis and other mainstream databases have built it in as a native data type.
The Hard Parts of Engineering It in Production
The real challenge usually isn't picking the right algorithm — it's robustly integrating it into a production system. How does the error rate evolve as data scales? How do you handle edge cases in hash collisions? How do you maintain consistency in a distributed environment? How do you migrate smoothly from an exact implementation to a probabilistic one? These are the engineering details that determine whether the optimization actually ships and saves 100TB.
Consistency in distributed environments is particularly tricky. Take Bloom Filters: in a multi-node setup, if each node maintains its own local filter independently, the same element may yield different query results on different nodes. But if you use a shared, centralized filter, every query requires a cross-network round trip, largely negating the latency benefits. A common engineering compromise is to periodically merge nodes' bit arrays via bitwise OR, accepting a brief inconsistency window in exchange for low-latency local lookups. Another often-underestimated issue is the quality of hash functions: the theoretical error rates of probabilistic data structures assume uniformly distributed hashing. If a hash function is biased for a particular input distribution, the actual false positive rate can be significantly higher than theory predicts. Non-cryptographic hash functions like MurmurHash and xxHash are widely used in these scenarios for their speed and uniform distribution.
What the Community Discussion Focused On
Judging by the engagement on Hacker News, engineers consistently find strong appeal in cases where math solves infrastructure problems. Posts like this resonate because they demonstrate the direct, real-world value of classic computer science theory — probability, hashing, information theory — in actual hyperscale systems, not just textbooks.
The discussion typically surfaces a few recurring themes: concerns about whether error rates cause real problems in long-tail scenarios, questions about specific implementation choices (why A instead of B), and rational skepticism about whether the reported savings are overstated. These discussions serve as a useful reminder to engineering teams: any approximation scheme requires rigorous monitoring and boundary testing to ensure that approximation errors don't cause unacceptable failures on critical paths.
Takeaways for Engineers
For engineers building large-scale systems, Cloudflare's ongoing memory optimization work offers several transferable lessons.
First, audit your data structures before you scale your hardware. Many so-called "out of memory" problems are fundamentally about inefficient data representation, not a genuine resource bottleneck.
Second, clarify what precision your business actually needs. If a query can tolerate a 0.1% false positive rate, then insisting on exact storage is wasteful. Identifying which scenarios can trade approximation for space savings is the prerequisite for this class of optimization.
Third, evaluate optimization gains in the context of scale. Saving a few hundred megabytes per machine may seem trivial in isolation, but multiplied across an entire fleet, it becomes 100TB in savings. Scale is itself a multiplier of returns.
Conclusion
Cloudflare's blog post reaffirms a simple but often overlooked truth: in infrastructure engineering, the most elegant and cost-effective optimizations typically come from algorithms and mathematics, not from endlessly stacking hardware. At sufficient scale, a smart data structure choice can deliver more value than a full data center expansion. For any technical team focused on system efficiency, this is an engineering paradigm worth revisiting again and again.
Related articles

Chinese Open-Source AI Cuts Costs to a Quarter: How Models Like Kimi Are Rewriting the Rules
Chinese AI models like Kimi and DeepSeek are cutting costs to a quarter of Western rivals. Here's how China went from trailing to competing at the frontier.

Fixing Fluid Typography: Combining Container Queries with @property
Fix fluid typography issues — font sizes growing past max-width containers and inconsistent sizes across multiple containers — using container query units and @property.

H3 HyperFlow: An Open-Weight Video Generation Model Focused on Camera Control and Consistency
H3 HyperFlow is an open-weight AI video generation model claiming better camera control, consistency, material detail, and balanced capabilities. Weights available on Hugging Face.