Saving 100 terabytes of memory by optimizing 1.1.1.1's DNS cache
- Infrastructure
- Programming
- Developer Tools
- Networking
Cloudflare’s post explains how it reduced memory use in the cache for 1.1.1.1, its public recursive DNS resolver, by stripping out structure it no longer needed after insert time. Cached DNS responses were being held in rich Rust objects built for mutability and convenience, even though once a response entered cache it was effectively read-only and mostly needed to be sent back out on the wire. The big changes were straightforward but high leverage: replacing `Vec` with boxed slices where capacity was useless, storing DNS records in a compact byte encoding instead of parsed structs, and deduplicating repeated owner names. At Cloudflare’s scale, that turned into roughly 100 TB less RAM across the fleet.
If you run a high-volume service, revisit any hot-path data that is written once and read many times. The easiest win may be changing the representation, not the algorithm, and those wins can stay invisible for years until scale makes them finance-level numbers.
-
blog.cloudflare.com
- Discuss on HN