Skip to content
FollowtheDamnCode

DNS

The distributed, cached lookup that turns a domain name into an IP address.

Big idea

DNS turns human-friendly names into IP addresses by walking a hierarchy of nameservers, and caching controlled by TTL keeps it fast, at the price that old answers linger until they expire.

The idea

Computers route traffic by IP address, but humans don't remember 142.250.80.14 — we remember google.com. DNS (Domain Name System) is the distributed, hierarchical lookup service that bridges the two: given a domain name, find the IP address it currently points to.

It's "distributed" in a load-bearing way — there's no single server that knows every domain's answer. Instead, resolution walks down a hierarchy, and heavy caching at every step is what keeps the whole system fast despite that.

Think of it like

Suppose you want to visit a colleague at a huge company campus. You ask your hotel concierge, who doesn't know them but knows the campus main reception. Reception doesn't know either, but sends you to the engineering building's front desk, which looks them up and gives you an exact room number. The concierge jots it down, so the next guest asking gets the answer instantly, at least until your colleague changes offices. DNS works this way: a resolver walks from root to TLD to authoritative nameserver, then caches the answer for as long as its TTL allows.

How a lookup actually happens

  1. Your browser asks a DNS resolver (usually run by your ISP or a public one like 8.8.8.8) to resolve the domain.
  2. If the resolver doesn't already have the answer cached, it asks a root nameserver, which doesn't know the answer either — but it knows which server handles the domain's top-level suffix.
  3. The TLD nameserver (for .com, .org, etc.) points the resolver to the authoritative nameserver for that specific domain.
  4. The authoritative nameserver holds the actual, current answer — the IP address the domain currently points to — and returns it.
  5. The resolver caches the answer for a duration set by the record's TTL, and hands it back to your browser.

That's a recursive query from the browser's point of view (it just wants a final answer) built out of several iterative hops underneath (each server answers with "ask this other server" rather than doing the walking itself).

A cold lookup for www.example.com

Record types you'll actually run into

  • A — maps a domain to an IPv4 address.
  • AAAA — maps a domain to an IPv6 address.
  • CNAME — an alias: "this domain is really just another domain, go resolve that one."
  • MX — where mail for this domain should be delivered.
  • TXT — arbitrary text, commonly used for domain ownership verification and email anti-spam policies (SPF/DKIM).

Why caching matters here

Every layer in the chain caches aggressively, governed by each record's TTL (time-to-live). A short TTL means changes propagate fast but every server does more repeat lookups; a long TTL means less lookup traffic but a change (like moving to a new server) takes longer to fully take effect everywhere, since cached resolvers keep serving the stale answer until their copy expires. That tradeoff is a real operational decision, not just a default to leave alone — teams often lower a record's TTL before a planned migration specifically so the cutover propagates faster.

By the numbers

SituationTypical time
Answer already cached on the device or OS~0 ms
Cached at the ISP's or a public resolver~1–20 ms
Resolver must walk root → TLD → authoritative~50–150 ms (three or more round trips)

TTLs decide how fast changes spread. A record with a TTL of 3,600 s can be served stale for up to an hour after you change it. Before a migration, lower the TTL (to ~60 s) a day ahead, switch, then raise it again. Most sites use 300 s to 1 day.

Scale: the root zone is served by 13 named root servers, but anycast spreads those names over more than 1,500 physical instances worldwide — the query goes to the nearest one.

A page that pulls assets from 10 different hostnames can pay 10 lookups on a cold start; that's part of why sites consolidate domains and browsers pre-resolve them (<link rel="dns-prefetch">).

A record has a TTL of 86,400 s (one day). You're moving the site to a new IP tomorrow. What should you do today?

Which record says "this name is just an alias — go resolve that other name instead"?

Key terms

  • DNS resolver — The server that does the lookup work on your behalf and caches the results.
  • Authoritative nameserver — The server that holds the real, current records for a specific domain.
  • TTL — How long a DNS answer may be cached before it has to be looked up again.
  • A record — A record that maps a domain name to an IPv4 address.
  • CNAME — An alias record that says one domain should be resolved as another domain.