How it works · 5 of 38 Foundation

How do DNS and a CDN work?

Finding the shop, and keeping copies near you

DNS & CDN: A phone finds a website by asking a chain of directories for its number (DNS) and keeping the answer for a time the site sets (the TTL); a CDN keeps copies of the site's files in buildings near its users, so most requests never travel to the far-off server.

Loading the animation…

Say it like this DNS turns a name into a server's number by asking a chain of directories, and everyone nearby reuses the answer for as long as its TTL says; a CDN keeps copies of files close to users so most requests never make the long trip.

Under the hood — for builders
The loop, on this card's shop
A resolver (the program that looks names up for you) asks three kinds of name server in turn. Each answer carries its own TTL (time to live, in seconds), so the first two steps are almost always already on the board.
The TTL trade-off, in numbers
One resolver re-asks at most once per TTL. Shorter means fresher answers after a move but more trips; longer means fewer trips and a longer wait after a move.
How 13 roots serve the world
The root is 13 named identities, a to m, run by 12 organisations (Verisign runs two). Each is copied to many sites sharing one address (anycast: the network delivers you to the nearest copy).
The CDN's shelf rules
The site tells the CDN how long to keep each file with a Cache-Control header ("max-age=86400": a day). A purge (invalidation) clears a copy early. Hit ratio: the share of requests served from the shelf.
Watch out
Lower the TTL a day or two before moving servers, so old answers expire fast. Mark logged-in pages "Cache-Control: private": a shelf that keeps one user's page can hand it to the next.
Measure it
DNS lookup time, cache hit ratio and time to first byte, measured from your users' cities, not your office.
Sources
RFC 1034 and 1035 (1987) · RFC 9111 (HTTP caching, 2022) · root-servers.org · Amazon CloudFront details page (750+ points of presence, 100+ cities) · JioCinema, IPL 2023 final (3.21 crore peak concurrent viewers).

What happens in the DNS & CDN animation, step by step?

  1. Your phone doesn't know where shop.example lives. It asks a resolver, usually run by your internet provider, to find out.
  2. The resolver asks round a loop: the root points to .com, .com points to the shop's own name server, and that one knows the number.
  3. The answer is kept for a time the shop chooses, its TTL. Until the candle burns down, every phone nearby gets the number at once.
  4. Your turn: the shop has moved to a new server. Drag the candle: how long should the old address be trusted?
  5. A CDN does the same for files: the first viewer's photo comes from far away and is kept on a shelf nearby; everyone after gets the copy.
  6. Copies can't take orders. When 3.2 crore people turn up at once, every order still reaches your servers. Next: load balancing and autoscaling.

What everyday example explains DNS & CDN?

Finding a friend's new flat. The society watchman asks the city office, which sends him to the area office, which sends him to the building's own register; he pencils the flat number in his notebook and trusts it for as long as your friend said (TTL). A CDN is the corner shop that keeps the bestsellers in stock, so you needn't go to the factory.

Why should a team care about DNS & CDN?

Before moving a site or switching providers, lower the TTL days ahead, or users keep reaching the old one; and decide what the CDN may keep, and for how long, because a stale copy is served as confidently as a fresh one.