CloudflareSebastiaan NeuteboomProblem & solution
How we saved 100 terabytes of memory by optimizing 1.1.1.1’s DNS cache
Summary
Cloudflare's Big Pineapple platform, which powers 1.1.1.1 and other DNS services, stores over 250 billion cache entries simultaneously. To decrease fleet-wide memory consumption, engineers implemented five changes to in-memory cache data structures. Key modifications included swapping growable types like Vec and String for Box slices to eliminate capacity overhead, combining distinct record sections into a single list indexed by offsets, omitting redundant owner domain names, and serializing record bytes into contiguous buffers. In benchmarks, these optimizations decreased per-entry memory footprints by 56% while improving cache lookup latency by 19% and insert throughput by 43%. Across production instances, the rollout reduced working-set memory by approximately 100 terabytes.
Context
Cloudflare's Big Pineapple platform stores over 250 billion DNS cache entries across its fleet. At that scale, a single wasted byte per entry equates to over 250 gigabytes of memory, with ECS-heavy data centers consuming even more space by caching multiple answer versions per query.
Approach / What changed
Engineers optimized Rust cache structs by replacing Vec and String fields with Box slices to remove capacity overhead, merging three separate record section lists into one list using u16 offsets, packing booleans into bitflags, dropping redundant owner domains from records when identical to the query domain, and serializing record data into contiguous Box<[u8]> byte buffers using reusable scratch space.
Takeaways
Replacing 8 Vec and String fields with Box slices removed capacity fields and excess heap allocations, saving 64 bytes per entry and over 15 terabytes across the fleet.
Merging answer, authority, and additional record sections into a single list with u16 offsets replaced two sets of 8-byte pointers and lengths, saving 28 bytes per entry.
Contiguous byte buffer layouts allowed direct copying of wire-format bytes for common types like A, AAAA, TXT, and DNSSEC records, cutting lookup latency by 5% and boosting insert throughput by 13%.
Source and freshness
- Source
- blog.cloudflare.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.