Skip to content
Episode 50 · Still on the old address

DNS deep dive: records, TTLs, GeoDNS and failover

Wednesday, 14:00: StayHub points api.stayhub.com at a new load balancer and switches the old one off an hour later. At 20:00, 30% of guests are still trying the old address, and failing.

DNS does more than turn names into numbers. It routes mail, steers visitors to the nearest server, and causes a surprising number of outages.

30 min intermediateDNS record types (A, AAAA, CNAME, MX, TXT, NS)DNS TTL trade-offsGeoDNS & DNS failoverDNS hierarchy and TTL cachingDNS resolutionHealth checks (liveness/readiness)
  1. Problem

    Your hotel platform runs in Europe and Asia, sends booking emails, uses a CDN and a dozen SaaS tools, and must keep working when a region goes down.

  2. Why the simple system fails

    A single A record pointing at one IP can't send users to the nearest region, can't route around a dead one, can't express 'mail goes elsewhere', and every change is held hostage by caches you don't control.

  3. Engineering concept

    Use the right record type for each job, choose TTLs deliberately, and let health-checked, location-aware authoritative DNS steer users, while remembering that every answer may be cached longer than you asked.

  4. Technology

    A, AAAA, CNAME, ALIAS, MX, TXT, NS, CAA records; recursive resolvers; TTL and negative caching; GeoDNS, latency-based routing, anycast, health-checked DNS failover.

  5. Trade-offs

    Low TTLs mean fast changes but more queries and more dependence on DNS availability. DNS steering is cheap and global but coarse and slow compared to a load balancer.

01

The problem

2 min
Wednesday, 20:00.
  1. Omar · On-call SRE
    At 14:00 we pointed api.stayhub.com at the new load balancer. At 15:00 we switched the old one off.
  2. Omar · On-call SRE
    At 20:00, 30% of guests still try the old address and fail. Our DNS provider shows the new one.
  3. You · Engineer at StayHub
    The record is right. So where does the old answer come from?
02

The big idea

4 min
The answer the world kept
The big idea

A DNS change is a request to caches you don't control. Lower the TTL first, and keep the old path alive until they agree.

My laptop showed the new IP only because its cache happened to expire. That's why DNS bugs look random: everyone's answer depends on when their cache last asked.

03

How it works

5 min
One lookup for api.stayhub.com
  1. 1
    Records, each with a TTL

    A record is one entry for a name: A (an IPv4 address), CNAME (another name), MX (mail), TXT (proofs), NS (who answers). Its says how many seconds anyone may keep a copy.

  2. 2
    The phone asks its resolver

    A resolver looks names up for a device, usually run by its internet provider, or a public one like 1.1.1.1. It caches answers.

  3. 3
    Cache hit: answer at once

    If the resolver's copy is younger than its TTL, it answers from it. Our provider is never asked, so our change is invisible.

  4. 4
    Cache miss: walk the chain

    Root → .com → our provider's nameservers, which give the current record. The resolver keeps it for the TTL.

  5. 5
    Steering with answers

    answers Jakarta with Singapore's address and Paris with Frankfurt's; drops a region that fails health checks. Both are bounded by the same caches.

04

Watch a decision being made

4 min
Worked example

You plan the next move; Lina checks it

Next month, api.stayhub.com moves again. Plan it so no guest sees an error, whatever their resolver cached.

  1. 1Read the current TTL from the source

    Ask the authoritative server, not a cache: TTL 86,400 s again.

    bash
    dig +norecurse api.stayhub.com A @ns1.dns-provider.example   # the truth
    dig api.stayhub.com A @1.1.1.1                              # what guests see

    Why: The old TTL decides how early you must start.

  2. 2Lower it one old TTL ahead

    Day −1, 14:00: TTL 60 s, same address. Wait at least 24 h.

    Why: Resolvers holding the 24-hour copy must expire it and pick up the short TTL first.

  3. 3Change, verify, keep the old path

    Day 0: new IP. Check at our provider, two public resolvers, a phone on mobile data. Switch the old load balancer off only after an hour near zero traffic.

    Why: Comparing authoritative and resolver answers separates "wrong record" from "stale cache".

  4. 4Restore a sensible TTL

    Raise it to 300 s; write it in the runbook.

    Why: 60 s forever means more lookups and more dependence on the DNS provider every minute.

The whole thing in one line: A one-line edit became a migration: shorten the TTL a full old TTL ahead, change, verify, drain, restore.
05

In real life

3 min
Different answers versus one address everywhere

AWS Route 53: steering with DNS answers

  • Publicly documents latency, geolocation and failover routing with health checks
  • Each region keeps its own IP; DNS picks one per resolver
  • Failover speed = health checks + TTL

Fits picking a region per user, cheaply.

Cloudflare: anycast

  • Publicly describes announcing the same IPs from data centres worldwide
  • Internet routing sends each user to a nearby location
  • A location is withdrawn in seconds, no DNS cache to wait for

Fits fast global failover, bought as a CDN or global load balancer.

06

What goes wrong

3 min
Changing a long-TTL record and expecting instant effect

Resolvers keep the old value until their copy expires.

Instead

Lower the TTL one full old TTL ahead.

Switching off the old target right after the change

Caches still send users there.

Instead

Switch off by traffic, not by the clock.

Clients that never re-resolve

Connection pools keep an IP for the life of the process.

Instead

Respect TTLs, cap connection lifetime (say 5 minutes), re-resolve after repeated connect errors.

07

Trade-offs

3 min
OptionFitsYou pay
Short TTLs (30–60 s)Failover endpoints; records about to changeMore lookups; a DNS outage hits sooner
Long TTLs (hours)NS, MX, TXT, stable recordsMistakes take hours to fix
Anycast / global load balancerFailover in secondsA paid provider or BGP skills
Thursday, 10:00. The DNS postmortem.
  1. Karim · CTO
    Simple fix: 30-second TTLs on everything. Then we can change anything, any time.
  2. Omar · On-call SRE
    Then a 10-minute DNS provider outage makes us unreachable for 10 minutes. With an hour, most guests wouldn't notice.
  3. Karim · CTO
    How often does a DNS provider go down?
08

Your job as tech lead

4 min

Claude Code can write the code for this. You still own the decisions, and you have to know what good looks like to accept or reject its work.

Decisions you own
  • The migration timeline: TTL 86,400 → 60 s at least 24 h before the change, 300 s afterwards.
  • When the old load balancer may go: after an hour near zero traffic, never on a schedule.
  • What DNS is for: coarse, slow steering. A 5% canary belongs at the load balancer.
Tell Claude Code
api.stayhub.com moves next month. Last time we changed the record with a 24-hour TTL and switched the old load balancer off after an hour; about 30% of requests failed until the next day. Don't touch DNS yet. Write docs/runbooks/api-dns-move.md: read the TTL from our authoritative server with dig, lower it to 60 s at least 24 hours ahead, change, verify at our provider, two public resolvers and mobile data, keep the old load balancer until traffic is near zero for an hour, then TTL 300 s. Give commands, expected output and rollback per step.
Check before you accept
  • The TTL lowering comes at least one old TTL (24 h) before the address change.
  • Verification queries the authoritative server and a public resolver separately.
  • The old load balancer's switch-off condition is a traffic number, not a time.
Red flags
  • It lowers the TTL and changes the address in the same edit.
  • It says "wait 24–48 hours for propagation" instead of reading the TTL.
  • It proposes weighted DNS for a 5% canary that must roll back in 30 seconds.
09

Check yourself

2 min
Q1/3Reasoning
Health checks run every 30 s and an endpoint is marked unhealthy after 3 consecutive failures. The record's TTL is 120 s. In the worst case for a well-behaved resolver that cached the answer just before detection, how many seconds after the region dies does it stop sending users there?
s
How confident are you?

Next episode: StayHub's partner API gets 40,000 requests a minute from one IP address, and you lead the response.

Finished?

Mark it complete to update your skill map.

Go deeper (optional)You don't need this to understand the lesson. Open it when a project needs the details: Technical deep dive, Interactive simulation, Visual diagram, Analogy, Check your understanding, Practice ladder, Explain it yourself.
10

Technical deep dive

Steering guests between regions
Worked example

You plan the next move; Lina checks it

Next month, api.stayhub.com moves again, this time to a load balancer in a new network. Plan it so no guest sees an error, whatever their resolver cached.

  1. 1Read the current TTL

    dig +norecurse api.stayhub.com @ns1.dns-provider.example → TTL 86,400 s again (someone reset it after the last move).

    Why: The old TTL decides how early you must start. Lina's check: always read it from the authoritative server, not a cache.

  2. 2Lower it one old TTL ahead

    Day −1, 14:00: set the TTL to 60 s, without changing the address. Wait at least 24 h.

    Why: Resolvers holding the 24-hour copy must expire it and pick up the new, short TTL. Only then can a change spread in about a minute.

  3. 3Make the change and verify

    Day 0, 14:00: point the record at the new IP. Check with dig at our provider and at two public resolvers, and from a phone on mobile data.

    Why: Comparing the authoritative answer with resolver answers separates "wrong record" from "stale cache".

  4. 4Keep the old path alive

    Leave the old load balancer running. Watch its request rate; switch it off only when it's near zero for an hour (expect a small tail from clients that ignore TTLs).

    Why: Wednesday's outage came from switching off a target that caches still pointed to.

  5. 5Restore a sensible TTL

    Raise the TTL to 300 s and note it in the runbook, with the reason.

    Why: 60 s forever means more lookups and more dependence on the DNS provider being up every minute. 300 s is a fair default for an entry point.

The whole thing in one line: You turned a one-line DNS edit into a migration: shorten the TTL a full old-TTL ahead, change, verify from several places, drain the old target before switching it off, then restore a normal TTL. Lina's only addition: write the runbook so the TTL doesn't drift back to a day.
TTLChange spreads inQuery loadGood for
30–60 sAbout a minute (plus misbehaving caches)Many cache misses; each adds a lookupFailover-managed endpoints; records you're about to change
300 sMinutesModerateDefault for app and CDN entry points
3,600 sUp to an hourLowMX, TXT, rarely changed records
86,400 sUp to a dayMinimalNS and truly static records
Before a planned change, lower the TTL at least one old-TTL period ahead.
Steering techniqueHow it decidesCaveat
GeoDNSLocation of the resolver (or client subnet, if the resolver sends it)A guest using a far-away public resolver can be sent to the wrong region
Latency-based routingMeasured latency from the resolver's network to each regionSame resolver-location caveat
Weighted recordsFixed percentages, e.g. 90/10Not exact because of caching
Failover recordsPrimary while healthy, else secondaryRecovery = detection + TTL + client caching
AnycastInternet routing to the nearest location announcing the same IPNot DNS logic at all; needs a provider or BGP skills
11

Interactive simulation

12

Visual diagram

Click a component

GeoDNS with health-checked failover across two regions.

13

Analogy

  • A hotel's address"Hotel Central is at 12 Main Street"DNSAn A record
  • A hotel's address"Ask for Main Street Hotels Group"DNSA CNAME pointing to another name
  • A hotel's address"Post goes to the station PO box"DNSAn MX record for email
  • A hotel's addressAddress cards travel agents keep for a yearDNSA long TTL, cached elsewhere
  • A hotel's addressAsian callers routed to the Asian centreDNSGeoDNS

Where the analogy breaks: travel agents might call to check. DNS caches never ask; they trust their copy until the TTL is up, and a few keep it even longer.

14

Check your understanding

Q1/3Recall
Match each need to the DNS record type:
Point www at your CDN's hostname
Deliver booking-reply emails to your mail provider
Prove domain ownership to a SaaS tool
Serve IPv6 clients
Restrict which CAs may issue your certificates
How confident are you?
15

Practice ladder

Step 1 · Trace

Trace a Singapore failover

Scenario Warm-up

api.stayhub.com uses latency routing with failover: health checks every 10 s, unhealthy after 3 failures, TTL 60 s. Singapore dies at 03:00:00.

Trace when each of these guests stops being sent to Singapore:

  1. Guest A's resolver cached the Singapore answer at 02:59:50.
  2. Guest B's resolver cached it at 03:00:25.
  3. Guest C's app resolved it at 02:58:00 and keeps an HTTP/2 connection open for as long as it works.
  4. Guest D's resolver has no cached copy.
Step 2 · Complete

Fill in Lina's migration runbook

Design Practice

Lina's runbook for moving partners.stayhub.com (TTL 3,600 s) to a new load balancer has two blank steps.

  1. Read the current TTL from the authoritative server.
  2. ___
  3. Change the A record to the new IP.
  4. Verify: authoritative server, 1.1.1.1, 8.8.8.8, and a phone on mobile data.
  5. ___
  6. Raise the TTL to 300 s and update the runbook.

Fill in steps 2 and 5 with times and the reason for each.

Step 3 · Solve

Move DNS providers without downtime

Design Practice

stayhub.com is hosted on the registrar's basic DNS. Its NS records have a TTL of 172,800 s (2 days). You want to move the zone to a managed DNS provider with health checks and latency routing.

The zone has about 40 records (A, CNAME, MX, TXT for email authentication, CAA). Booking emails and certificate renewals must keep working throughout.

Plan the move so that no guest, email or certificate renewal fails at any point.

Step 4 · Decide

Canary the new search API with DNS?

Decision Stretch

The search team wants to send 5% of traffic to a new search API version and roll back within 30 seconds if errors rise. They propose weighted DNS records: search.stayhub.com → 95% old IP, 5% new IP, TTL 60 s.

The alternative: a single DNS name for the load balancer, and a 95/5 weighted rule on the load balancer that can be changed instantly.

Write a short decision: "We chose X over Y because…, accepting the risk of…".

16

Explain it yourself

Your Asia region just went down. Explain to your product manager why some Asian guests recovered in one minute, some in four, and a few only after reinstalling the app.

0 words