How a name becomes an address
No single computer knows every name. DNS is a hierarchy, read from right to left: api.shop.example. is the name api, inside shop, inside example, inside the root (the invisible final dot).
When your app looks up a name, several servers take part:
- Your device asks a recursive resolverRecursive resolverThe DNS server that looks up names for clients by asking other DNS servers, and caches the answers.Open in glossary →: usually your internet provider’s, or a public one like Cloudflare’s
1.1.1.1or Google’s8.8.8.8. It does the legwork for you. - If the resolver doesn’t know the answer, it asks a root server: “where is
api.shop.example?” The root doesn’t know, but it knows who runs.exampleand says “ask them”. - The resolver asks the TLD server (top-level domain) for
.example. It answers: “shop.exampleis handled by these name servers”. - The resolver asks the authoritative server for
shop.example, the one the domain’s owner set up (often at Cloudflare, Route 53 or the registrar). It knows the real answer:203.0.113.10. - The resolver gives the answer to your device and keeps a copy.
Every answer comes with a TTLTTL (time to live)How long a cached copy may be used, for example how many seconds a DNS answer may be cached.Open in glossary → (time to live) in seconds: how long it may be cached. With a TTL of 300, the resolver answers everyone who asks in the next five minutes from its copy, without asking anyone. Your phone, browser and operating system keep copies too. That makes DNS fast (most lookups take a few milliseconds and never leave your provider) and it means a change isn’t seen everywhere at once: it spreads as old copies expire.
- Hierarchy: root (13 server names,
atom.root-servers.net, served by well over a thousand anycast instances), TLDs (.com,.rs,.dev), then delegations via NS records plus glue A/AAAA records when the name server lives inside the zone it serves. - Recursive vs authoritative: resolvers recurse and cache; authoritative servers only answer for their zones. Clients run a stub resolver (the OS), which adds its own cache (
mDNSResponderon macOS and iOS,systemd-resolved, Android’snetd), and runtimes cache again (the JVM keeps successful lookups 30 seconds by default, failures 10; browsers about a minute). - TTL trade-off: long TTLs mean fewer queries and resilience when the authoritative servers are down; short TTLs mean fast changes and failover. 300 seconds is a common default for records you may need to move; 3,600 or more for stable ones. Some resolvers clamp very low TTLs or serve stale answers on errors (RFC 8767), so “TTL 30” doesn’t guarantee 30-second failover.
- Transport: UDP port 53; if a response doesn’t fit (EDNS buffer, now usually 1,232 bytes), the server sets the TC flag and the client retries over TCP. Firewalls that block TCP 53 break large responses (DNSSEC, many TXT records). Encrypted variants: DNS over TLS (853) and DNS over HTTPS (443), used by browsers and Android’s Private DNS.
- DNS-based routing: GeoDNS or latency-based answers, weighted records for gradual cutovers, health-checked failover records. All limited by caching: clients keep using the old answer until their TTL expires, and a resolver’s location, not the user’s, decides the “nearest” answer unless the resolver sends EDNS Client Subnet.
Predict the output
You query the same public resolver twice, a few seconds apart. The domain's record has a TTL of 300. What do you see in the TTL column the second time?
$ dig +noall +answer @1.1.1.1 example.com
example.com. 223 IN A 104.20.23.154
$ dig +noall +answer @1.1.1.1 example.com # a few seconds laterThe second number in each line is the remaining TTL. The resolver fetched the record at some point, cached it, and now hands out its copy with the time left: 223, then a few seconds later 219. When it reaches 0, the next query makes the resolver ask the authoritative server again and the countdown restarts. (A big public resolver is many machines, so successive answers can come from different caches.)
# the answer, short
dig +short api.github.com
# the full answer section with TTLs
dig +noall +answer github.com
# ask a specific resolver (here Cloudflare's), not the one your OS uses
dig @1.1.1.1 github.com
# follow the whole chain yourself: root -> .com -> github.com's servers
dig +trace github.com
# ask the authoritative server directly: no cache in between
dig +short NS github.com
dig @ns-1283.awsdns-32.org github.com
# what your OS resolver returns (includes /etc/hosts)
dscacheutil -q host -a name github.com # Linux: getent hosts github.comWorked example: a cold lookup
Nobody has asked for api.shop.example in a while, so every cache has expired. Your phone opens the app.
- Phone. The app asks the operating system for the address. The OS has no cached copy, so it sends a question over UDP to the resolver your Wi‑Fi configured, say
1.1.1.1. - Resolver, cache. It has nothing for
api.shop.example, nothing forshop.example, but it does have the.exampleservers cached from earlier lookups (they have a TTL of two days). So it skips the root. - TLD server. The resolver asks a
.exampleserver. It replies with a referral: “shop.exampleis served byns1.dnshost.netandns2.dnshost.net”. The resolver caches that too. - Authoritative server. The resolver asks
ns1.dnshost.net, which answers:api.shop.example A 203.0.113.10, TTL 300. - Back to the phone. The resolver caches the answer for 300 seconds and sends it to the phone, which caches it as well. The whole thing took perhaps 40 milliseconds.
- Everyone else. For the next five minutes, every user of that resolver who opens the app gets the answer from its cache in a couple of milliseconds.
The root servers are rarely asked anything: their answers have long TTLs and every resolver keeps them.
Deep diveDNS as a load balancer and failover switchInterview favorite
“Can you use DNS to spread traffic across regions and fail over when one goes down?” Yes, with limits worth naming.
What it does well: returning several A records (clients pick one or try them in order), steering users to the nearest region (latency- or geo-based answers from Route 53, Cloudflare, NS1), weighted answers for a 5% canary of a new cluster, and taking a region out of the answers when health checks fail. It works for any protocol and needs no proxy in the path.
Where it falls short:
- Caching delays failover: a client keeps the old answer until the TTL expires, and some resolvers and runtimes keep it longer. With a 60-second TTL, expect most traffic to move within a few minutes and a long tail after.
- Clients hold connections: a mobile app with a keep-alive connection never looks up the name again while the connection lives. Failover also needs the dead region to close connections.
- Coarse location: the answer is chosen by the resolver’s address. EDNS Client Subnet helps where resolvers send it (Google does, Cloudflare’s 1.1.1.1 deliberately doesn’t).
- No load awareness: DNS doesn’t know how busy each region is unless the provider feeds that back.
That’s why large systems use DNS for coarse steering between regions and anycast (the same IP announced from many locations, routed by BGP to the closest one) or L4/L7 load balancers for fast, per-connection decisions. Cloudflare, Google’s front ends and the root servers themselves use anycast. See CDNs.
- Stub → recursive resolver → root → TLD → authoritative; every layer caches for the TTL (OS, browser, JVM 30 s by default).
- TTL trades change speed against query load and resilience; resolvers may clamp TTLs or serve stale.
- UDP 53 with TCP fallback on truncation; DoT 853, DoH 443.
- DNS steering: multiple records, geo/latency, weighted, health-checked failover. Limited by caching and long-lived connections; anycast and load balancers for fast decisions.
dig +noall +answer @1.1.1.1 shop.example # cached answer, TTL counting down
dig +trace shop.example # the full delegation chain
dig @$(dig +short NS shop.example | head -1) shop.example # authoritative, uncachedCheck this part
Who usually does the work of finding an address for your phone?
A record has a TTL of 3,600. You change its address. When do all users see the new one?
DNS failover switched the record 10 minutes ago (TTL 60), yet a mobile app still talks to the dead region. Most likely why?
Large DNS responses fail through a corporate firewall, small ones work. Likely cause?