Stage 1 · Foundations · Easy · 12 min

DNS and geo-routing

DNS turns a name such as shop.example.com into a server's IP address. Follow one lookup, see why answers are cached, and how DNS sends users to a nearby region.

What each interview level is expected to know

Learn first: The client–server model

After this lesson you can:

  • Follow one DNS lookup from the local cache to the server that holds the answer.
  • Predict how long an old address keeps being used after a change, from its TTL.
  • Explain how one name can send users in different places to different regions.

Start here

See it in 60 seconds

Finding the address behind a name

DNS finds the address behind a name by asking a chain of servers once, then answering from a saved copy until its TTL runs out.

Scene 1 of 6 · Ask the resolver

Your browser needs the address for shop.example.com, so it asks a resolver, a server that looks names up.

Your browserYour browserResolverResolverRoot serverRoot server.com server.com serverName server, example.comName serverexample.com
  • Your browser — healthy
  • Resolver — healthy
  • Root server — healthy
  • .com server — healthy
  • Name server — example.com — healthy
This lookup took about
not shown yet
  1. Ask the resolver. Your browser needs the address for shop.example.com, so it asks a resolver, a server that looks names up.
  2. Ask a root server. The resolver asks a root server, which knows only where the .com servers are.
  3. Ask the .com server. A .com server knows which name server keeps the records for example.com.
  4. Get the address. That name server answers 203.0.113.7, and says to keep it for 300 seconds: the TTL.
  5. Answer and remember. The resolver passes the address back after about 110 ms, and keeps a copy until the TTL runs out.
  6. The next lookup is quick. For the next 300 seconds, anyone using this resolver gets the address from its copy in about 20 ms.
  7. Now you try. How long ago did this resolver last look up shop.example.com? Set the seconds. For example: 120 s is under the 300 s TTL, so the resolver answers from its copy in about 20 ms. The copy stays good for 180 more seconds; after that, the next lookup takes the full trip again.

Scene 1 of 6: Ask the resolver. Your browser needs the address for shop.example.com, so it asks a resolver, a server that looks names up.

Key points

  1. DNS turns a name such as shop.example.com into an address a computer can connect to.
  2. A full lookup asks a root server, then a .com server, then the site's own name server.
  3. Resolvers keep each answer for its TTL, so most lookups take one short trip.
  4. A long TTL means fewer slow lookups, but a changed address takes longer to reach everyone.

Go deeper in the Request flow lab →

In plain words

You type shop.example.com into a browser. The network cannot route to a name: it needs a number, such as 203.0.113.7. That number is an . The (DNS) is the lookup service that turns the name into the address. The browser gets the address first, then connects to the server.

The lookup takes a few steps. The browser asks a , usually run by the internet provider. If the resolver has no saved answer, it asks the root servers, then the servers for .com, then the shop's own name servers. Browsers and resolvers keep the answer for a set time, its , so later lookups skip all of that.

The problem it solves

People remember names, but networks route by number. A site's address also changes: it moves to a new host, or adds servers in other regions. DNS lets the name stay the same while the address behind it changes.

Why it matters

A client must look up a name in DNS before it can connect, so DNS sits in front of almost every system. The lookup adds a delay to the first request. DNS can also send each user to the nearest region, and move traffic away from a failed one. When DNS fails, users without a cached answer cannot find the site, even if its servers are healthy.

A worked example

Suppose a domain's DNS answer has a TTL of 300 seconds, and a browser sends one request every second. One real DNS lookup then covers the next 299 requests, since 300 − 1 = 299, before a new lookup is needed.

Think of it like…

Think of the contacts list on your phone. You tap a name, and the phone dials the number stored for it. You never need to remember the number.

Where this analogy stops working

A name that maps to a number is the useful part. But DNS is not one list in one place. A resolver asks a chain of servers, and each knows only the next step. Answers are also cached, so after a change some users get the old address for a while.

Try it

See it working

Guided walkthroughOpen the full lab →

Lab · Foundations

Request flow

Follow one request for a product page, part by part: DNS, a CDN edge near the user, and on a miss the origin far away. Pick which copies exist, then step forward and back and watch the time add up.

Try it

Where the address is known

The resolver answers from its copy: about 20 ms.

The CDN edge
The cache at the origin

With these settings: Answered by the database after 248 ms. The trip to the origin and back took 200 of those ms, so a CDN copy would have saved the most.

Browser, in PuneBrowserin Punewaiting for addressDNS resolver, name to address, NOWDNS resolvername to addressNOWCDN edge, in MumbaiCDN edgein MumbaiLoad balancer, origin, VirginiaLoad balancerorigin, VirginiaAPI gateway, checks each callAPI gatewaychecks each callProduct service, builds the answerProduct servicebuilds the answerCache, RedisCacheRedisDatabase, PostgreSQLDatabasePostgreSQL
  • Browser — in Pune — healthy — waiting for address
  • DNS resolver — name to address — healthy — NOW
  • CDN edge — in Mumbai — healthy
  • Load balancer — origin, Virginia — healthy
  • API gateway — checks each call — healthy
  • Product service — builds the answer — healthy
  • Cache — Redis — healthy
  • Database — PostgreSQL — healthy
  • Request
  • Answer
  • Miss: sent on
  • Read
  • Nothing found
  • Save a copy
Step 1 of 15

Step 1 of 15 · DNS resolver

Done: The browser asks DNS for the address

What happens
The browser has a name, shop.example.com, but the network needs an IP address.
Why
Nothing can be sent until the browser knows where to send it.
What changes
The resolver has a saved answer, so it can reply at once.
Next
DNS answers after 20 ms

Event log

14 more to go. Press a line to go back to that step.

Time so far
0ms
Lines crossed
1
Parts that did work
2
Answered by
not yet

Step 1 of 15: DNS resolver. The browser asks DNS for the address. The browser has a name, shop.example.com, but the network needs an IP address.

What this model simplifies
  • Every time here is an example value, not a measurement. The edge is 2 ms away and the origin 100 ms away each way. The cache takes 1 ms and the database 15 ms.
  • The connections are already open, so there is no TCP or TLS handshake to wait for. The HTTP lesson shows what those cost.
  • Each part does one thing at a time, and nothing fails. A real edge may also check with the origin before it serves an old copy.

Mechanics

How it works

DNS turns a name into an address. The pictures follow one lookup: a browser asks for shop.example.com, and the answer is 203.0.113.7.

  1. Check local caches

    DNS turns a name such as shop.example.com into an IP address such as 203.0.113.7. The browser first checks its own , then asks the operating system. If either has the answer, no network call is needed.

  2. Ask a recursive resolver

    If not, the computer asks a recursive resolver. This is a server, often run by your internet provider, that finds the answer for you. It answers from its own cache when it can. With nothing cached, it starts at a root server.

  3. Follow the chain

    Pick a case to follow below

    With this case: With nothing saved, the lookup took 4 trips and about 110 ms before the browser could even connect.

    Browser, wants the addressBrowserwants the addressResolver, finds it, saves it, NOWResolverfinds it, saves itnothing savedNOWRoot server, knows .com, .org…Root serverknows .com, .org….com server, knows example.com.com serverknows example.comName server, for example.comName serverfor example.com
    • Browser — wants the address — healthy
    • Resolver — finds it, saves it — healthy — NOW — nothing saved
    • Root server — knows .com, .org… — healthy
    • .com server — knows example.com — healthy
    • Name server — for example.com — healthy
    • Question
    • Answer
    Step 1 of 5

    Step 1 of 5 · Resolver

    Done: The browser asks the resolver

    What happens
    The browser and the computer have nothing saved for shop.example.com, so the computer asks its resolver.
    Why
    The resolver does the searching, so the computer sends only one question.
    What changes
    The resolver has nothing saved either.
    Next
    The resolver asks a root server
    Time so far
    10ms
    Trips over the network
    1
    Address found
    –

    Step 1 of 5: Resolver. The browser asks the resolver. The browser and the computer have nothing saved for shop.example.com, so the computer asks its resolver.

    The root server points to the servers for .com. Those are top-level domain (TLD) servers. The .com server points to the authoritative name server for example.com. That server holds the real record and returns the IP address.

    In the picture, each trip from the resolver to a name server takes about 30 ms there and back. These are round example times, not measurements. With nothing saved, the lookup takes four trips and about 110 ms.

    Switch to the resolver having the answer saved. Then the lookup is one trip of about 20 ms. When the browser has it saved, nothing goes over the network. That is why most lookups are fast: someone nearby asked for the same name a short time ago.

  4. Return and cache the answer

    Pick a case to follow below

    With this case: With a TTL of 300 seconds, users of this resolver get the old address for up to 240 more seconds. In return, it asks the name server less often.

    Browser, wants the addressBrowserwants the addressResolver, finds it, saves itResolverfinds it, saves itsaved 203.0.113.7Root server, knows .com, .org…Root serverknows .com, .org….com server, knows example.com.com serverknows example.comName server, for example.com, NOWName serverfor example.comnow 203.0.113.50NOW
    • Browser — wants the address — healthy
    • Resolver — finds it, saves it — healthy — saved 203.0.113.7
    • Root server — knows .com, .org… — healthy
    • .com server — knows example.com — healthy
    • Name server — for example.com — healthy — NOW — now 203.0.113.50
    • Question
    • Old answer
    Step 1 of 3

    Step 1 of 3 · Name server

    Done: The shop moves to a new server

    What happens
    The name server for example.com now says 203.0.113.50. The old server, 203.0.113.7, is switched off.
    Why
    Nothing tells the resolvers. Each one finds out only when it asks again.
    What changes
    The resolver still holds the old answer it saved 60 seconds ago.
    Next
    A browser asks for shop.example.com
    Name server says
    203.0.113.50
    Resolver saved
    203.0.113.7
    60 s ago, TTL 300 s
    Browser gets
    –
    not yet

    Step 1 of 3: Name server. The shop moves to a new server. The name server for example.com now says 203.0.113.50. The old server, 203.0.113.7, is switched off.

    What these pictures simplify. These pictures use round example times: 20 ms to the resolver and back, 30 ms to each name server and back. Real times depend on where the servers are. A real resolver runs on many machines, and a browser may cap how long it keeps an answer.

    The resolver sends the IP address back with a time to live (TTL), such as 300 seconds. Each cache on the way keeps the answer for up to that long. A short TTL lets you change the address quickly, but causes more lookups.

    In the picture, the shop moves to a new server, 203.0.113.50, a minute after the resolver saved the old address. Nothing tells the resolver about the move.

    With a TTL of 300 seconds, the resolver keeps handing out the old address for four more minutes. With 30 seconds, its copy has run out, so it asks again and gets the new one. The cost is that it asks up to 10 times as often. Teams often lower the TTL a day before a planned move, then raise it again after.

  5. One name, different answers

    The name server does not have to give everyone the same address. With geo-routing, it looks at where the question came from and returns the address of the nearest region. Say the site runs in Frankfurt and Singapore. A user in Paris gets the Frankfurt address, and a user in Jakarta gets the Singapore one.

    The question usually comes from the user's resolver, not from the user. So the name server guesses the user's place from the resolver's address. A user far from their resolver can be sent to the wrong region. Some resolvers pass on part of the user's address to fix this, a feature called EDNS Client Subnet.

Use it when

  • Sending each user to a nearby region (geo-routing): the name server answers with the address of a region near the user.
  • Moving traffic away from a failed region: point the record at a healthy one, and users follow as their cached answers run out.
  • Keeping one fixed name in front of servers you replace: clients keep using the name, and only the record changes.

Skip it when

  • Fast between single servers: clients keep a dead address until its TTL ends. A with health checks reacts much sooner.
  • Finding copies of a service that start and stop all day: a cached answer is soon out of date. A with fits better.

Check yourself

Your laptop looks up www.example.com for the first time. Which server holds the address the resolver finally returns?

Judgement

Trade-offs and how it fails

What you give up

Performance
A long TTL means fewer lookups, so most requests skip the DNS delay. A short TTL means more lookups, but a changed address reaches users sooner.
Consistency
After a change, each user keeps the old address until their cached answer runs out. So for a while some users reach the old servers and some the new. That lasts about one TTL, and longer where a resolver or an app ignores the TTL.

Failure modes

  • The DNS provider goes down. In October 2016 an attack flooded the provider Dyn with traffic. For hours, many users could not reach Twitter, Netflix or Reddit, though those sites' own servers were running.
  • A wrong record with a long TTL. Resolvers keep the bad address for up to the full TTL, and you cannot clear most of their caches.
  • Failover slower than planned: some resolvers and apps keep an answer past its TTL, so some users still reach the dead address.
  • Geo-routing picks the wrong region: the name server often sees only where the resolver is, not where the user is.

In the real world

  • AWS Route 53 offers latency-based routing, which answers each user with the region that responds fastest for them. Source: AWS Route 53 docs: latency-based routing (checked 14 October 2026)
  • Public resolvers such as Cloudflare's 1.1.1.1 use anycast: one IP address is announced from many cities, so queries reach a nearby server.

Trade-offs to be ready to discuss: Dns ttl tradeoff

Check yourself

Why lower a DNS record's TTL a day before moving to new servers?

Interview

What interviewers look for

  • When you fail over through DNS, state the TTL and what it costs: "With a 60-second TTL, most users move within about a minute."
  • For a multi-region design, say how users reach the nearest region: geo-routing in DNS, or anycast, where one IP address is announced from many places.

Say it out loud: What changes if you set a DNS TTL to 1 second, or to 86,400 seconds (24 hours)?

You move your site to a new IP address. The old DNS record had a TTL of 24 hours. What happens right after the change?

Expected depth by interview level

Levels describe the depth interviewers probe, not years of experience. Choose a level on the learning path to highlight it.

JuniorExpected
What DNS does and why answers are cached.
MidExpected
TTLs and DNS-based routing.
SeniorUseful
Geo-routing and failover through DNS, and the TTL delay.
StaffUseful
DNS as one piece of a multi-region failover plan.

Practice

Apply it

Three harder questions

The first two use the idea on a new case. The last asks you to judge a design.

Apply it

A site runs in Frankfurt and Singapore, with geo-routing. A user in Jakarta works through a company network whose DNS resolver is in Frankfurt. Which address does the user most likely get?

Apply it

Your browser and operating system have no answer for shop.example.com. Your resolver looked it up 1 minute ago, and the TTL is 300 seconds. What happens next?

Judge a design

A team plans failover by pointing the DNS record at a standby server when the main one dies. The TTL is 1 hour. What is the weakness?

Next: HTTP, TCP and UDP, the rules that carry your data once the client has the address.

Go deeper

Sources and further reading

First-hand sources to check this page against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.