DNS deep dive
Go inside the internet's contacts list: records, resolvers, caches and the TTL, why a one-line DNS change left 30% of StayHub's guests on a dead address, and how to move safely.
The lesson in text
Click a paragraph to hear it.01Still on the old address
Wednesday, 14:00. StayHub moves its API to a new load balancer. Omar changes one line: api.stayhub.com now points to 198.51.100.20 instead of 203.0.113.10. Then, an hour later, to save money, the old load balancer is switched off.
At 20:00, about 30% of API requests are still going to the old address, and failing. Yet the DNS provider's dashboard shows the new address, and on your laptop everything works.
When we followed one click to a website, DNS was the internet's contacts list: a name in, a number out. Today we go inside it. Because that contacts list isn't one list. It's millions of copies, and each copy decides for itself when to look again.
02What a record says
Start with what's stored. For every name, the DNS provider keeps a few records. An A record gives an address: api.stayhub.com is at 198.51.100.20.
A CNAME says: this name is really another name, ask for that one instead. That's how StayHub's photos point at the CDN. MX says where email goes. TXT holds proofs, like the one ACME checks before it issues a certificate. And NS says which servers hold the truth for the whole domain.
| Type | Example | Means |
|---|---|---|
| A | api.stayhub.com → 198.51.100.20 | An address |
| CNAME | photos.stayhub.com → stayhub.cdn.example | Another name: ask for that one |
| MX | stayhub.com → mail servers | Where email goes |
| TXT | _acme-challenge.stayhub.com → a proof | Proofs, like the one ACME checks |
| NS | stayhub.com → ns1.dns-provider.example | Who holds the truth for the domain |
Every record also carries a number that matters more than it looks: the TTL, time to live. It's how many seconds anyone may keep a copy of the answer without asking again. StayHub's API record had a TTL of 86,400 seconds. That's one whole day.
03How a lookup travels
Your phone doesn't ask StayHub's DNS provider directly. It asks a resolver: usually your internet provider's, or a public one like 1.1.1.1. A resolver looks names up for millions of devices, and it remembers what it finds.
If the resolver already holds a copy younger than its TTL, it answers at once. That's a cache hit, and it's the usual case. StayHub's DNS provider is never asked, so whatever we just changed is invisible.
If it has no copy, it walks a chain. It asks a root server: who handles .com? Then the .com servers: who handles stayhub.com? Then StayHub's provider, the authoritative servers, which give the current record. The resolver keeps that answer for the TTL.
A cache hit takes a millisecond or two. Walking the chain costs a few round trips, tens of milliseconds. That's why caches exist, and why TTLs tend to be long.
It's also why DNS bugs look random. Two guests ask in the same minute and get different answers, because each resolver last asked at a different time. Your laptop simply happened to ask after the change.
04Address cards
Picture your hotel moving across town. Thousands of travel agents have your address on a card, and every card says: valid for one day. They won't phone to check. Until their card expires, they keep sending guests to the old building.
That's exactly Wednesday. At 14:00, every resolver that had asked in the previous 24 hours held a card that said 203.0.113.10, valid for a day. And at 15:00, the old building was locked.
Wed 14:00 A record → 198.51.100.20 (TTL still 86,400 s)the changeWed 15:00 old load balancer 203.0.113.10 switched offto save moneyWed 20:00 ~30% of API requests still go to the old addressand failThu ~14:00 the last day-long copies expiresettled, 24 h laterWhile the old load balancer was running, those guests were simply on the old path, and it worked. Switching it off turned "still on the old address" into "connection refused". The record was fine. The plan wasn't.
It settled only on Thursday around 14:00, a full day after the change, when the last cards expired. There is no mysterious "propagation" to wait for. There are copies, and each one expires on its own clock.
05Moving without errors
Here's the plan for the next move, the one you write and Lina checks. Step one, a day ahead: lower the TTL to 60 seconds, keeping the same address. Then wait at least one old TTL, 24 hours, so every day-long card has expired and been replaced by a one-minute card.
Step two: change the address. Now every cache picks up the new one within a minute.
Step three: verify from several places. Ask the authoritative server directly: that's the truth. Ask two public resolvers and a phone on mobile data: that's what guests see. If they disagree, it's a stale cache, not a wrong record.
Step four: keep the old load balancer running and watch its traffic. Switch it off only after an hour near zero. By traffic, never by the clock.
Step five: raise the TTL back to 300 seconds. Sixty seconds forever means far more lookups, and less protection if the DNS provider has a bad day.
- 1Day −1Lower the TTL to 60 s, same address. Wait at least one old TTL (24 h).
- 2Day 0Change the address. Caches pick it up within a minute.
- 3VerifyAuthoritative server (the truth) vs two public resolvers and a phone on mobile data (what guests see).
- 4DrainKeep the old load balancer until its traffic stays near zero for an hour.
- 5AfterRaise the TTL to 300 s. Write it all in the runbook.
06Steering with answers
DNS can also give different answers to different people. StayHub is adding a Singapore region for its guests in Asia. With latency-based DNS, a resolver in Jakarta gets Singapore's address, and one in Paris gets Frankfurt's.
It can fail over, too. Health checks test each region every 10 seconds, and after three failures in a row, DNS stops handing out that region's address. Thirty seconds to notice, plus the 60-second TTL: about a minute and a half before guests move.
That's fine for losing a whole region. But DNS is a coarse tool. It steers by the resolver's location, not the guest's, and nothing changes faster than the TTL. To send 5% of traffic to a new version, use the load balancer instead.
Big CDNs use another trick called anycast: the same address announced from many places at once, so the internet's routing picks the nearest one. A location can be withdrawn in seconds, with no cache to wait for. StayHub doesn't run that itself; it buys it with a CDN.
07The cache in your own code
One more cache hides where nobody looks. One Sunday at 02:00, StayHub's payment provider moved to new addresses for maintenance. Its DNS was correct, with a 60-second TTL.
But checkout kept failing. A lookup run on a booking server showed the new address. The booking service itself had looked the name up once, when it started, and kept the old address for as long as it ran.
Checkout failed with every DNS dashboard green, until the servers were restarted at 05:10. The fix: respect the TTL in the client, close connections after a few minutes so they reconnect, and look the name up again after repeated connection errors.
Sun 02:00 payment provider moves to new addressesits DNS correct, TTL 60 sdig on a booking server → the new addressDNS is finebooking's HTTP client → still the old addressresolved once, kept foreverSun 05:10 servers restarted, checkout works3 h 10 min of failures- ✓ Respect the TTL in the client
- ✓ Close connections after a few minutes so they reconnect
- ✓ Look the name up again after repeated connection errors
08Your job as lead
At the postmortem, Karim proposes 30-second TTLs on everything. Omar answers: then a ten-minute outage at our DNS provider makes us unreachable for ten minutes. The policy: short TTLs only where fast change matters, long ones elsewhere, lowered ahead of planned changes. Written in a runbook, because forgetting it is exactly how Wednesday happened.
When Claude Code plans a DNS change, check the order. Is the TTL lowered at least one old TTL before the address changes? Is it verified both at the source and at public resolvers? And is the old target switched off by traffic, not by time?
Red flags: lowering the TTL and changing the address in the same edit. "Wait 24 to 48 hours for propagation" instead of reading the TTL. And a client that looks a name up once and never again.
Let's recap. DNS is millions of copies, each kept for the TTL. Resolvers answer from their cache and only ask the source when their copy expires. Lower the TTL a full old TTL ahead, change, verify, drain by traffic, restore. And your own code is a cache too. Next: proxies and firewalls, the gatekeepers in front of StayHub.
Check yourself
0/10 answered1What does a DNS record's TTL control?
2You change an A record whose TTL is 86,400 seconds. How long can some resolvers keep handing out the old address?
3After the change, your laptop reaches the new address but 30% of guests still hit the old one. Why?
4api.stayhub.com has a 24-hour TTL and must move next week. What do you do first?
5Claude Code's plan: "Change the A record to the new IP and set the TTL to 60 s in the same edit, check with dig from my machine, shut the old load balancer down after an hour." What do you say?
6When may the old load balancer be switched off after a DNS move?
7The payment provider moved IPs. A lookup on our server shows the new address, yet checkout keeps failing until a restart. What's the cause?
8Health checks run every 10 seconds, a region is dropped after 3 failures, and the TTL is 60 seconds. Roughly how long until guests leave a failed region?
9You want to send 5% of guests to a new version and be able to roll back within seconds. Claude Code suggests weighted DNS. What do you answer?
10Karim wants 30-second TTLs on every record so anything can change any time. What's the better policy?
Save your progress — create a free account
Free. No card. Your finished lessons follow you to any device, and you can ask questions in the community.
Create my free accountEvery lesson is free while we build. Lock in €9/month for later.
The first 100 members keep the founding price for as long as they stay. Reserving is free: no card, nothing is charged.
See the founding offer