Infrastructure
Cloudflare Slashes 100 TB from DNS Cache with Memory Redesign
A comprehensive overhaul of how Cloudflare stores DNS cache entries trimmed memory footprints by more than half while improving both speed and throughput.
InfoQ
Cloudflare has completed a significant overhaul of its 1.1.1.1 DNS resolver's in-memory cache, achieving a 56% reduction in per-entry memory usage and reclaiming approximately 100 TB of memory across its entire infrastructure. The optimization also delivered measurable performance gains, including a 43% boost in cache insertion speed and a 19% reduction in lookup latency.
The Scale of DNS Caching#
The Big Pineapple DNS platform, which powers 1.1.1.1, manages over 250 billion cache entries at any moment. The sheer volume meant that even modest per-entry savings would compound into substantial fleet-wide gains—a point highlighted by systems engineer Sebastiaan Neuteboom, who noted that "it's not every day you get to save 100 terabytes of memory."
Five Successive Optimizations#
The team implemented five distinct refinements to how cache data is represented in Rust. The first swap—replacing general-purpose Vec and String types with more fixed-size Box<[T]> and Box<str> alternatives—eliminated 64 bytes per entry and freed more than 15 TB across the fleet. Subsequent tweaks consolidated DNS answer, authority, and additional records into a single list with compact offset pointers, bit-packed Boolean flags, and eliminated redundant domain name storage by deriving them from the cache lookup key instead.
The most difficult problem was handling Rust's enum types. Initial boxing of larger variants added allocation overhead and damaged memory locality. The solution was radical: replace enums entirely and store all record data as a contiguous byte buffer formatted in standard DNS wire format. This eliminated per-record allocation costs while improving CPU cache performance.
Production Results#
The rollout proceeded gradually between May 18 and July 6, 2026. Memory resident on individual instances shrank dramatically:
- p99 memory: 9.3 GB → 5.3 GB
- p90 memory: 6.5 GB → 3.8 GB
Benchmarks confirmed the improvement: each cache entry now consumes 420 bytes instead of 953, and total allocations dropped from 1.1 KB to 461 bytes. Frequently accessed record types can now be copied directly into responses, while entries containing domain names still require minimal parsing for DNS name compression.

