HeadlinesBriefing favicon HeadlinesBriefing.com

Optimizing Cloudflare's DNS Cache: 100TB Saved

Hacker News •
×

Cloudflare's DNS cache stores over 250 billion entries, and a single byte waste costs 250GB across the fleet. By making five successive changes to how entries are stored in memory, they cut the per-entry footprint by over 50%, freeing roughly 100 terabytes of RAM—equivalent to 130 Gen 13 servers. The optimizations also improved performance: insert throughput rose 43% and lookup latency dropped 19%, proving that reducing memory usage can speed up operations.

The key changes involved replacing Vec and String types with Box<[T]> and Box<str>, which eliminated unnecessary capacity fields and heap over-allocation. Each cache entry originally used 8 Vec/String fields, each carrying a 24-byte overhead; switching to boxed slices saved 64 bytes per entry. This was measured through custom allocator benchmarks and validated in production, where memory savings were significant without sacrificing speed.

The article details the technical process, from benchmarking with representative traffic (56% A, 25% AAAA, 19% TXT records) to rolling out changes across data centers. It emphasizes that small per-entry savings compound massively at scale, and that careful profiling can lead to both memory and performance gains.