What it is
The Domain Name System maps names such as www.example.com to the data clients need to connect: IP addresses (A and AAAA records), mail servers (MX), aliases (CNAME) and the servers responsible for a zone (NS). It is a distributed, hierarchical, heavily cached database. No single server knows every name; each zone's authoritative servers know their own names, and resolvers find and cache the answers.
Why it exists
Packets are routed by IP address, but people and configuration files use names. Names also add a level of indirection: a service can move to new addresses without every client being reconfigured. DNS provides that mapping at internet scale by delegating each part of the namespace to its owner and letting everyone cache what they learn.
How it works
The players.
- The stub resolver in your operating system (and a cache in the browser) checks local caches and the hosts file, then sends the question to one configured recursive resolver.
- The recursive resolver (your ISP's, your company's, or a public one such as 1.1.1.1 or 8.8.8.8) does the work. It answers from cache when it can and otherwise queries the hierarchy itself.
- Root servers know which servers handle each top-level domain. There are 13 root server names, each served by hundreds of anycast instances.
- TLD servers (for
.com,.org,.de, …) know which name servers handle each domain below them. - The authoritative servers for
example.comhold the actual records.
A cold lookup. The resolver asks a root server for www.example.com. The root answers with a referral: the NS records (and addresses) of the .com servers. The resolver asks a .com server, which refers it to the example.com name servers. The resolver asks one of those and gets the A record, say 203.0.113.10 with a TTL of 300 seconds. It returns that to the stub and caches every record it learned. Towards your device the resolver is recursive (you get a final answer); towards the hierarchy it is iterative (it follows referrals itself). Modern resolvers also use QNAME minimisation, sending each server only the part of the name it needs.
Caching and TTLs. Every record has a TTL in seconds, set by the zone owner. A cache may reuse the record until the TTL runs out, then must ask again. TTLs differ per record: NS records for TLDs typically live for a day or two, while A records for services are often 60–300 seconds. That is why a real resolver almost never asks a root server: the delegation for .com is nearly always cached, and only the short-lived leaf record is re-fetched.
Negative caching. "This name does not exist" (NXDOMAIN) and "this name has no record of that type" (NODATA) are cached as well, for the negative TTL: the smaller of the TTL of the zone's SOA record and the SOA's minimum field (RFC 2308).
Transport. Queries normally use UDP on port 53, falling back to TCP for large answers; DNS over TLS and DNS over HTTPS encrypt the hop between the stub and the resolver.
When to use it
DNS is how clients find almost every public service, and it is the right place for things that change slowly: which addresses or which CDN serve a name, mail routing, ownership proofs (TXT records), and coarse traffic steering such as latency- or geography-based answers. Inside a platform, DNS-based service discovery works well when instances change at most every few minutes.
When not to
- As a fast failover switch: caches hold old answers for at least the TTL.
- For precise load balancing: resolvers cache one answer for many users, so traffic follows resolvers, not users, and shifts in coarse steps.
- For rapidly changing membership (autoscaling instances every few seconds): use a load balancer or a service registry that clients query directly.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Long TTL (hours) | Fewer queries, faster lookups, resilience if your DNS provider has an outage | Changes and failovers take hours to propagate |
| Short TTL (seconds to a minute) | Changes take effect quickly | More queries and cost, more lookups that pay a round trip; some resolvers raise very low TTLs |
| DNS-based steering (geo, latency, health-checked answers) | Global traffic control without extra hops | Coarse and delayed by caching; clients behind a distant resolver get its location |
| Public resolver (1.1.1.1, 8.8.8.8) | Large shared cache, privacy features | Geo-steering may see the resolver's location rather than the user's (EDNS Client Subnet mitigates) |
Alternatives
- Anycast: announce one IP from many locations; the network routes each user to the nearest. Failover happens in routing, without changing DNS.
- A load balancer or global front door with a stable address: health checks move traffic behind the address within seconds.
- Service registries (Consul, Kubernetes endpoints, cloud service discovery) for internal services whose instances change often.
- Hard-coded IPs in tightly controlled environments: no lookup, no indirection, no flexibility.
Failure modes
- Stale answers after a change: caches keep the old record for its TTL. Browsers, operating systems and runtimes (some application runtimes historically cached lookups for the process lifetime) add their own layers, and open connections never re-resolve.
- Negative caching surprises: a name looked up before it was created stays "missing" for the negative TTL.
- Authoritative outage: once cached records expire, resolution fails for everyone. Use more than one DNS provider for critical zones, and do not set TTLs so low that a short provider outage empties every cache.
- Resolver outage or slowness: every new connection on that network stalls. Clients often have a secondary resolver configured, with a timeout before they try it.
- Misconfiguration: a wrong NS delegation, a missing glue record or an expired domain takes everything down at once, and the fix itself is subject to TTLs.
In production
Lower TTLs a day or more before a planned migration (at least one old TTL ahead), make the change, then raise them again. Keep critical names on two independent DNS providers. Monitor resolution from several regions and resolvers, not only from inside your network. Create records before announcing them. For fast failover, keep DNS pointing at stable addresses (load balancers, anycast IPs) and fail over behind them; health-checked DNS failover still waits for caches.
Common misconceptions
- "A TTL of 60 seconds means everyone switches within a minute." It bounds staleness for caches that honour it; some do not, and clients with open connections never ask again.
- "Every lookup goes to the root servers." Almost none do: TLD delegations are cached for days.
- "DNS propagation is the new record spreading out." Nothing is pushed. Caches expire and fetch the new answer on their own schedule.
- "If the name does not resolve yet, I'll just create it." The failed lookup may now be cached for the negative TTL.
Interview angle
Explain the path (stub → recursive → root → TLD → authoritative) and point out that caching makes almost every lookup cheap. Then talk about the operational side: what TTL you would choose and why, how you would migrate a service to new addresses, and why you would not rely on DNS alone for failover. Mentioning negative caching, multiple DNS providers and anycast shows practical experience.
Model assumptions
This lesson is a scripted walk-through, not a simulation: every packet is placed by hand to show the order of queries and answers, and the caches are labels. Latencies are illustrative one-way values (1 ms inside the device, 8 ms to the recursive resolver, 12 ms to a root server, 15 ms to the TLD server, 30 ms to the authoritative server, about 1 ms processing per server). The cold lookup assumes an empty resolver cache, which is rare in practice because root and TLD referrals are cached for a day or two. Real resolvers also retry other servers on timeouts, use TCP or encrypted transports, and may prefetch popular records before they expire.