---
title: "How we saved 100 terabytes of memory by optimizing 1.1.1.1’s DNS cache"
description: "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."
---

# How we saved 100 terabytes of memory by optimizing 1.1.1.1’s DNS cache

[Cloudflare](https://yomu.fyi/company/cloudflare) · Sebastiaan Neuteboom · Aug 27, 2026

**Type:** Problem & solution

## 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%.

**Tags:** [Caching](https://yomu.fyi/topic/caching), [Performance](https://yomu.fyi/topic/performance), [Refactoring](https://yomu.fyi/topic/refactoring), [Rust](https://yomu.fyi/topic/rust), [Scalability](https://yomu.fyi/topic/scalability)

- Source: [Cloudflare](https://blog.cloudflare.com/dns-cache-memory-optimization-1111)
- Source URL: https://blog.cloudflare.com/dns-cache-memory-optimization-1111
- Ingested by Yomu: 2026-08-27T20:00:45.149Z

[Read original post](https://blog.cloudflare.com/dns-cache-memory-optimization-1111)
