<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/understanding-dns-can-pay-off-dnybuvhw4" -->

---
title: Understanding DNS can pay off | daily.dev
description: A commentary video walks through Cloudflare&#x27;s blog post detailing how they cut memory usage in their 1.1.1.1 DNS cache (written in Rust) by 100 terabytes...
canonical: https://daily.dev/posts/understanding-dns-can-pay-off-dnybuvhw4
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Understanding DNS can pay off | daily.dev
og:description: A commentary video walks through Cloudflare&#x27;s blog post detailing how they cut memory usage in their 1.1.1.1 DNS cache (written in Rust) by 100 terabytes...
og:url: https://daily.dev/posts/understanding-dns-can-pay-off-dnybuvhw4
og:image: https://api.daily.dev/og/posts/DNYBUvhW4.png
og:image:alt: Understanding DNS can pay off
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Understanding DNS can pay off

**[ThePrimeTime](https://daily.dev/sources/primeagen)** · 13 min read · 4 upvotes · 0 comments

## Summary

A commentary video walks through Cloudflare's blog post detailing how they cut memory usage in their 1.1.1.1 DNS cache (written in Rust) by 100 terabytes across their fleet. Optimizations covered include replacing Vec with boxed slices to eliminate unused capacity, collapsing repetitive record structures (answer/authority/additional) into a single struct, omitting redundant owner strings already present in the cache key, and boxing DNS record enums to avoid padding waste from oversized variants like NAPTR records. Results cited from Cloudflare's own data show P99 memory dropping from 9.3GB to 5.3GB (43% reduction), P90 dropping 42%, cache insert throughput rising from 625K to nearly 900K entries/sec, and lookup latency improving 19%.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=dCwWXEI1-lA>

## Questions this post answers

### How did Cloudflare reduce memory usage in the 1.1.1.1 DNS cache written in Rust?

Cloudflare cut memory usage by replacing Vec fields with boxed slices to remove unused capacity overhead, collapsing repetitive answer/authority/additional record fields into a single struct, omitting the owner string when it duplicates the cache key, and boxing DNS record enum variants so oversized types like NAPTR (136 bytes) don't force padding on smaller ones like A records (4 bytes). Together these changes saved roughly 100 terabytes of memory across their fleet.

_See how memory-layout tricks like these get surfaced and discussed on daily.dev for Rust developers optimizing at scale._

### Why does using an enum to represent different DNS record types (A, AAAA, NAPTR) waste memory in Rust?

Rust enums must be sized to fit their largest variant, so if a NAPTR record takes 136 bytes while an A record takes only 4 bytes, every enum instance consumes 144 bytes regardless of which variant it actually holds. Since A and AAAA records make up over 80% of DNS traffic, most records waste more than 120 bytes on padding; boxing the record data onto the heap fixes this at the cost of some cache locality.

_Developers weighing enum layout trade-offs in Rust can follow deep dives like this on daily.dev._

### What memory and performance improvements did Cloudflare see after optimizing its 1.1.1.1 DNS cache data structures?

P99 memory usage dropped from 9.3GB to 5.3GB, a 43% reduction, and P90 memory dropped from 6.5GB to 3.8GB, a 42% reduction. Cache insert throughput rose from about 625,000 to nearly 900,000 entries per second, and lookup latency fell by roughly 150 nanoseconds, about 19% faster, with instances holding fuller caches seeing the largest absolute savings.

_Track real-world performance wins like this on daily.dev when evaluating Rust for high-scale infrastructure._

---

Tags: [#rust](https://daily.dev/tags/rust), [#cloudflare](https://daily.dev/tags/cloudflare), [#dns](https://daily.dev/tags/dns), [#data-structures](https://daily.dev/tags/data-structures)

[View this post on daily.dev](https://daily.dev/posts/understanding-dns-can-pay-off-dnybuvhw4)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Understanding DNS can pay off","url":"https://daily.dev/posts/understanding-dns-can-pay-off-dnybuvhw4","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/understanding-dns-can-pay-off-dnybuvhw4"},"datePublished":"2026-09-03T13:22:17.005Z","dateModified":"2026-09-08T12:09:59.585Z","description":"A commentary video walks through Cloudflare's blog post detailing how they cut memory usage in their 1.1.1.1 DNS cache (written in Rust) by 100 terabytes...","image":"https://i.ytimg.com/vi/dCwWXEI1-lA/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/dCwWXEI1-lA/sddefault.jpg","isAccessibleForFree":true,"articleSection":"ThePrimeTime","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"ThePrimeTime","logo":"https://media.daily.dev/image/upload/s--J5-GjDeo--/f_auto/v1704628081/logos/primeagen.jpg","url":"https://daily.dev/sources/primeagen"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/understanding-dns-can-pay-off-dnybuvhw4","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":4},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"rust,cloudflare,dns,data-structures","timeRequired":"PT13M","video":{"@type":"VideoObject","name":"Understanding DNS can pay off","description":"A commentary video walks through Cloudflare's blog post detailing how they cut memory usage in their 1.1.1.1 DNS cache (written in Rust) by 100 terabytes...","thumbnailUrl":"https://i.ytimg.com/vi/dCwWXEI1-lA/sddefault.jpg","uploadDate":"2026-09-03T13:22:17.005Z","duration":"PT13M","url":"https://api.daily.dev/r/DNYBUvhW4","embedUrl":"https://www.youtube.com/embed/dCwWXEI1-lA"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"ThePrimeTime","item":"https://daily.dev/sources/primeagen"},{"@type":"ListItem","position":3,"name":"Understanding DNS can pay off"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/understanding-dns-can-pay-off-dnybuvhw4#faq","mainEntity":[{"@type":"Question","name":"How did Cloudflare reduce memory usage in the 1.1.1.1 DNS cache written in Rust?","acceptedAnswer":{"@type":"Answer","text":"Cloudflare cut memory usage by replacing Vec fields with boxed slices to remove unused capacity overhead, collapsing repetitive answer/authority/additional record fields into a single struct, omitting the owner string when it duplicates the cache key, and boxing DNS record enum variants so oversized types like NAPTR (136 bytes) don't force padding on smaller ones like A records (4 bytes). Together these changes saved roughly 100 terabytes of memory across their fleet. See how memory-layout tricks like these get surfaced and discussed on daily.dev for Rust developers optimizing at scale."}},{"@type":"Question","name":"Why does using an enum to represent different DNS record types (A, AAAA, NAPTR) waste memory in Rust?","acceptedAnswer":{"@type":"Answer","text":"Rust enums must be sized to fit their largest variant, so if a NAPTR record takes 136 bytes while an A record takes only 4 bytes, every enum instance consumes 144 bytes regardless of which variant it actually holds. Since A and AAAA records make up over 80% of DNS traffic, most records waste more than 120 bytes on padding; boxing the record data onto the heap fixes this at the cost of some cache locality. Developers weighing enum layout trade-offs in Rust can follow deep dives like this on daily.dev."}},{"@type":"Question","name":"What memory and performance improvements did Cloudflare see after optimizing its 1.1.1.1 DNS cache data structures?","acceptedAnswer":{"@type":"Answer","text":"P99 memory usage dropped from 9.3GB to 5.3GB, a 43% reduction, and P90 memory dropped from 6.5GB to 3.8GB, a 42% reduction. Cache insert throughput rose from about 625,000 to nearly 900,000 entries per second, and lookup latency fell by roughly 150 nanoseconds, about 19% faster, with instances holding fuller caches seeing the largest absolute savings. Track real-world performance wins like this on daily.dev when evaluating Rust for high-scale infrastructure."}}]}
```

