DNS — The Domain Name System

How a human-friendly name like example.com becomes a machine address your browser can actually reach — and why that lookup quietly decides whether anything else works.

DNS in 30 seconds

  • What: the internet's phone book — turns a name like example.com into an IP address.
  • When: it's the very first step of nearly every request, so if it's slow or wrong, nothing else works.
  • How: a cached hierarchy walked in steps — resolver → root → TLD → authoritative server.
  • TTL: each record says how long it may be cached — long means fast but slow to change, short means the reverse.
  • Before a migration: lower the TTL first, switch, then raise it — or clients cling to the old IP.
  • Bonus role: coarse routing — round-robin DNS, geo-DNS, and DNS failover, reacting in seconds, not instantly.

A phone book for the whole internet

Imagine you want to call a friend, but you only know their name — not their number. You flip through a phone book: look up the name, read off the number, then dial. You never memorize the number; you just trust the book to have it. DNS is that phone book for the internet. You type a name you can remember (example.com), and DNS hands back the number a computer actually needs to connect (an IP address like 93.184.216.34).

The twist is that no single phone book could possibly hold every name on earth and stay up to date. So the internet uses a chain of smaller books that hand you off toward the right answer — and almost everyone keeps a sticky note of recent lookups so they rarely have to flip through the whole thing. Those two ideas, hierarchy and caching, are the entire heart of DNS.

The problem it solves

Computers talk to each other using numeric IP addresses, but people can't remember those. DNS is the internet's phone book: it translates a name you type (example.com) into the IP address of a server that can answer. It's one of the first things that happens on every request, and when it's slow or wrong, nothing else works — so it's worth understanding well.

What breaks if there's no DNS

To feel why DNS exists, picture the web without it. Every site, every API, every image would be reachable only by its raw IP address, and you'd have to know and type those numbers by hand.

  • You'd memorize numbers, not names. https://93.184.216.34 instead of example.com — for every service you use.
  • Moving a server would break every link. If a site changed hosting, its IP changes, and every bookmark and hard-coded reference would silently point at the wrong machine.
  • You couldn't spread load or fail over. A name that can point at different machines over time is what lets you add servers, shift regions, or route around a dead data center. A bare IP can't do any of that.
  • One brittle list. Early networks literally shared a single hosts file listing every machine. That stopped scaling the moment the internet had more than a few hundred hosts.

DNS fixes all of this by adding one layer of indirection: a stable, human-friendly name in front of an address that's free to change underneath it. That indirection is the whole trick — and it's why DNS is both essential and a surprisingly powerful routing tool, as we'll see.

The core idea, plainly

No single machine knows every name on the internet, so DNS is a hierarchy that's resolved in steps. Your computer asks a resolver; the resolver asks the root servers which know where .com lives; the TLD servers for .com point to the authoritative server for example.com; and that server returns the real IP. Each step caches its answer, so the full walk only happens occasionally.

Reading a domain name right-to-left

The hierarchy is hiding in plain sight inside the name itself. A domain name is read from right to left, broadening from the specific host to the global root — the dots are the boundaries between levels:

Every dot is a level in the hierarchy (pseudocode)
www   .   example   .   com   .
 |         |           |     |
 |         |           |     +--  root            (the implied trailing dot)
 |         |           +--------  TLD              (.com registry)
 |         +--------------------  second level     (example.com's owner)
 +------------------------------  host / subdomain (a specific machine or service)

# Resolution walks this chain the same direction DNS delegates authority:
# root  ->  .com TLD  ->  example.com authoritative  ->  'www' record

That final, usually-invisible dot after com is the root — the top of the tree. Seeing a name this way makes the resolution steps feel obvious: each level knows only where to find the next level down, never the whole answer.

Walking the hierarchy, step by step

Here's the full walk in code. Notice the very first thing it does is check the cache — because in the overwhelming majority of real lookups, that's where the story ends.

A resolver walking the hierarchy (pseudocode)
def resolve(name):                       # e.g. "www.example.com"
    if cache.has(name):
        return cache.get(name)           # cheap: most lookups stop here

    ns = root_servers                    # start at the top
    ns = ask(ns, name).referral          # root -> ".com" TLD servers
    ns = ask(ns, name).referral          # TLD  -> authoritative for example.com
    answer = ask(ns, name).record        # authoritative returns the A record (IP)

    cache.set(name, answer, ttl=answer.ttl)   # cache until the TTL expires
    return answer
The resolver walks the hierarchy once, then serves cached answers.

Where answers get cached — it's caches all the way down

The hierarchy would be painfully slow if every lookup climbed all the way to the root. It doesn't, because almost every layer keeps a short-lived copy of recent answers. A single lookup might be satisfied at any of these rungs:

  • The browser cache — browsers remember recent resolutions for a short window, so clicking around one site rarely re-resolves.
  • The operating system cache — the OS keeps its own resolver cache shared by every app on the machine.
  • The recursive resolver's cache — your ISP's or company's resolver serves millions of users, so popular names are almost always already cached there.
  • The authoritative server — only reached when nobody above has a fresh answer. This is the source of truth.

Because of this stacking, the expensive full walk is the exception, not the rule. The thing that decides how long each of these copies stays valid is a single number attached to every record: the TTL.

Caching and TTLs

Every DNS record carries a TTL (time to live) — how long it may be cached. A long TTL means fast lookups and less load, but slow propagation when you change where a name points. A short TTL makes changes take effect quickly but increases lookup traffic. This single setting is why DNS changes can take minutes or hours to be seen everywhere.

TTL choiceYou getYou give upGood for
Long (hours/days)Fast lookups, little DNS load, cheapChanges take a long time to reach everyoneStable records that rarely move
Short (seconds/minutes)Changes propagate quicklyMore lookup traffic, slightly slower first hitsRecords you expect to change or fail over
Lowered temporarilyQuick switch when you need itExtra load only during the windowThe run-up to a planned migration

The gap caching can't fill — stale answers

Caching is what makes DNS fast, but it's also the source of its most confusing failure. The moment you change a record, every cache that still holds the old answer keeps serving it until its copy expires. There is no way to instantly 'push' the new value — caches only refresh when their TTL runs out.

This is why a DNS change can look like it 'worked for me but not for my teammate': you resolved fresh, they're still inside an old cached TTL. The fix isn't a magic flush button — it's planning around the TTL ahead of time. Lower it before the change so the window of staleness is short, and only raise it again once the new value has fully propagated.

The common record types

A DNS record is just a line that maps a name to some value, tagged with a type. You'll meet a handful constantly, and knowing what each does removes a lot of mystery from DNS config screens:

TypeMaps a name to…Everyday use
AAn IPv4 addressThe basic 'name → server' lookup
AAAAAn IPv6 addressThe same thing, for IPv6
CNAMEAnother name (an alias)Point www.example.com at example.com or a CDN hostname
MXA mail serverTells senders where email for the domain goes
TXTArbitrary textDomain verification, email anti-spoofing (SPF/DKIM)
NSThe authoritative name serversDelegates who answers for the zone
What a resolver returns (pseudocode)
example.com.   300   IN   A      93.184.216.34   # TTL = 300s
example.com.   300   IN   A      93.184.216.35   # round-robin pair
www.example.com. 300 IN   CNAME  example.com.     # alias to another name
example.com.   3600  IN   MX  10 mail.example.com. # where email for the domain goes

DNS as a system-design tool

DNS isn't only name lookup — it's a lightweight routing and availability tool. Because a name can point at different addresses, you can use it to steer traffic. Three patterns show up constantly:

  • Round-robin DNS — return several IPs for one name and let clients spread across them. Crude balancing with no health awareness.
  • Geo-DNS — return a different IP depending on where the query came from, so users hit the nearest region.
  • DNS failover — monitor your endpoints and stop returning the IP of a data center that's gone dark.

It's coarse-grained — TTL caching means it reacts in seconds-to-minutes, not instantly — so it complements, rather than replaces, a real load balancer.

The gap DNS routing can't fill — why you still need a load balancer

DNS routing looks like it could be your whole load balancer, but it has a hard ceiling, and the reason is caching again. Once a client has resolved a name, it reuses that IP for the whole TTL — DNS doesn't see the individual requests, so it can't react to them.

QuestionDNS routingA real load balancer
How fast can it react?Seconds to minutes (TTL-bound)Instantly, per request
Does it know a server is down?Only via slow failover checksYes — active health checks
Can it balance evenly?Roughly, and clients cache unevenlyYes — real-time, per-connection
GranularityPer lookupPer request / per connection

So use DNS for the coarse decision — which region or which pool — and let a load balancer behind that name make the fine decision — which healthy server, right now. They're layers, not competitors.

DNS is the quiet first hop of the entire internet — it runs before your load balancer, your CDN, or your app ever sees a request, which makes it both essential and an easy thing to forget.

Why it matters

  • It's step zero of every request, so a DNS failure looks like a total outage no matter how healthy your servers are.
  • The TTL is the hidden knob behind 'why did my change take hours?' — understanding it saves real incident time.
  • DNS doubles as a coarse routing layer, giving you regional proximity and failover before traffic hits your infra.

If ignored

  • You treat DNS as invisible and leave it as an unguarded single point of failure.
  • You change a record without lowering its TTL and spend hours confused about stale clients.
  • You lean on round-robin DNS as if it were a real load balancer and get uneven, un-health-checked traffic.

Where it fits

  • Sits at the very front of the request path, before the reverse proxy and load balancer.
  • Acts as a global, coarse-grained traffic director across regions and data centers.
  • Complements — never replaces — the fine-grained balancing a real load balancer does.

Related topics

Interview lens

Questions it unlocks

  • What happens, step by step, when you type a URL and press enter?
  • Why did your DNS change take hours to take effect?
  • How can DNS help with regional routing or failover?

60-second answer

DNS resolves a name to an IP by walking a cached hierarchy — resolver, root, TLD, authoritative — and the answer's TTL controls how long it's cached. That TTL is the knob behind slow propagation, so before a migration I lower it, switch, then raise it. Beyond lookup, DNS doubles as coarse routing: round-robin for simple balancing, geo-DNS for regional proximity, and DNS failover to steer away from a dead region — understanding it reacts in seconds, not instantly.

Common traps

  • Forgetting DNS is the very first step and a potential point of failure.
  • Changing a record without first lowering its TTL and then wondering why it's stale.
  • Treating DNS round-robin as a substitute for a real load balancer.

Search topics

↑↓ to move · Enter to open · Esc to close