Design DNS
Understanding the Problem
📖 What is DNS? The Domain Name System turns names people can remember, like
www.example.com, into the IP addresses computers connect to. It's a distributed, hierarchical database: no single server knows every name, but every name can be found by asking the right servers in order, starting from the root. Almost every connection on the internet starts with a DNS lookup, so it has to be fast and it can never go down.
"Design DNS" can mean two different systems, and it's worth asking which one your interviewer wants. A recursive resolver (your ISP's, or a public one like 8.8.8.8 or 1.1.1.1) answers lookups for clients by walking the hierarchy and caching the results. An authoritative DNS service (like Route 53 or Cloudflare DNS) hosts domain owners' records and answers for them. They're two halves of the same lookup, so we'll design a provider that runs both, and give most of our time to the parts interviewers push on: caching, update propagation and availability.
Functional Requirements
Core Requirements
- Clients should be able to resolve a domain name and record type (A, AAAA, CNAME, MX, TXT...) to its current records.
- Domain owners should be able to create, update and delete records in their zones.
- Record changes should be served by our authoritative servers quickly, and reach clients as cached copies expire.
- Domain owners should be able to return different answers by location or health (traffic steering), for example to fail over away from a dead data center.
Below the line (out of scope)
- Domain registration (the registrar and registry business of buying
example.com). - Running the root or TLD servers. We'll use them, not build them.
- Private DNS inside a VPC, and service discovery.
Non-Functional Requirements
Ask your interviewer for scale. We'll assume a large provider:
- Authoritative: 10 million hosted zones with about 500 million records, answering 2 million queries per second at peak.
- Recursive resolver: a public resolver answering 10 million queries per second globally.
Core Requirements
- The system should answer queries with low latency: under 10 ms for cached or authoritative answers from a nearby location, and well under 100 ms for most cache misses.
- The system should be extremely available. DNS is the first step of every request, so an outage takes down everything behind it. Target 100% for authoritative answers in practice, meaning no single failure (server, site or network) can stop answers.
- Record changes should be live on every authoritative server within about a minute.
- The system should resist abuse: cache poisoning, DDoS against our servers, and being used as an amplifier against others.
Below the line (out of scope)
- Strong consistency. DNS is eventually consistent by design: resolvers may serve a cached answer until its TTL runs out.
- Query logging and analytics pipelines.
Back-of-the-envelope:
Authoritative data fits in memory. 500M records × roughly 200 bytes each (name, type, TTL, data, plus index overhead) is about 100 GB. That fits in RAM on a large server, so every authoritative server can, if we want, hold every zone and answer every query from memory without touching disk. That's a huge simplification. Lookups are hash table reads, and a single well-tuned server can answer hundreds of thousands to over a million queries per second.
Resolver traffic is mostly cache hits. Names follow a steep popularity curve: a few million names (big sites, CDNs, ad and analytics domains) get most queries. Resolvers typically answer most queries from cache. If 85% of our 10M QPS is hits, the resolver still makes 1.5M upstream queries per second, and each miss can cost several upstream round trips. Raising the hit ratio is the main lever on resolver latency.
The two halves have opposite problems. The authoritative side is a small, read-only dataset that needs to be copied everywhere and changed safely. The resolver side is a big, constantly churning cache. Separating them in your head early makes the rest of the conversation easier.