Why you need it

People remember names like shop.com, but computers find each other by numbers called IP addresses. Something has to turn the name into the number, billions of times a day, quickly, and keep working when a site moves to a new number.

Think of it like this

Your phone's contact list. You tap "Mum", and the phone looks up the number. If Mum changes her number, your phone keeps calling the old one until the contact is updated.

Where you’ll find it

  • Cloudflare and Google: Run free public lookup services that anyone can use: 1.1.1.1 and 8.8.8.8.
  • AWS: Route 53 answers lookups for millions of sites, and can send each visitor to the nearest or healthiest server.
  • The whole internet: Starts every lookup at 13 named root servers, run by 12 organisations, copied to well over a thousand places worldwide.

What to know first

IP address. The number that finds a machine on the internet, like 93.184.215.14.

Resolver. The helper that does the lookup for you, usually run by your internet provider or a public service like 1.1.1.1.

TTL. Time to live: how many seconds an answer may be kept and reused before asking again.

How it works

  1. Your device asks a resolver. You type shop.com. Your laptop asks its resolver: "what number is shop.com?".
  2. The resolver asks down a chain. It asks a root server who handles .com, then asks the .com servers who handles shop.com, then asks shop.com's own name server for the number. Three short questions.
  3. Everyone keeps the answer for a while. The resolver and your laptop both keep the answer for the TTL, so the next lookup is instant. This is the note your laptop keeps in the animation.
  4. Changes spread slowly. When the site moves, old answers live on until their TTL runs out. With a TTL of an hour, some visitors keep going to the old address for up to an hour. Teams lower the TTL a day before a planned move.
  5. It can also share out traffic. A name can return several addresses, or a different one depending on where you are, which spreads visitors over many places before they even reach a Load balancing balancer.

An example

shop.com points to 1.2.3.4 with a TTL of 3,600 seconds (one hour).

On Monday the team moves to a new server at 5.6.7.8 and updates DNS. Visitors who looked up the name recently keep using 1.2.3.4 for up to an hour, and get errors if the old server is already off.

Better: on Sunday lower the TTL to 60 seconds. On Monday, after the change, everyone moves over within about a minute. Keep the old server running a little longer, just in case.

Further reading

  • How DNS works, DNSimple (comic). A short illustrated story of one lookup. The friendliest start. Start with this one.
  • What is DNS?, Cloudflare Learning Center. A clear, deeper walk through each step and each kind of server.
  • Implement DNS in a weekend, Julia Evans. Build a tiny resolver yourself, in a few hundred lines. The best way to really get it.