4. DNS
1
The picture to keep in your head2
4.1 Why do we need names at all?3
4.2 What are the parts of a domain name?4
4.3 What happens, step by step, when a name is looked up?5
4.4 What kinds of DNS records are there?6
4.5 What is a TTL, and why does DNS cache so much?7
4.6 How can DNS spread users across servers or send them to the nearest one?8
4.7 Why do DNS changes "take time to propagate"?9
4.8 What happens when DNS fails?10
Memory card and where the analogy breaks11
Practice: five levels12
Interview questions13
Solutions14
Sources15
Code lab4. DNS
4.8 What happens when DNS fails?
3 min read+10 XP
In your phone's contacts: Your phone works, Ravi's phone works, but your contacts app has crashed and you don't remember his number. You can't call him, even though nothing is wrong with either phone.
In the system: If users can't turn your name into an IP address, your site is down for them, even if every server is healthy. Two well-documented examples:
- October 2016, Dyn: a large DDoS attack, driven by the Mirai botnet of infected internet-connected devices, hit the managed DNS provider Dyn. Many well-known sites that used Dyn for DNS became unreachable for many users, though their own servers were running.
- October 2021, Facebook: a mistaken command during maintenance disconnected Facebook's backbone network. Its DNS servers were built to withdraw themselves from the internet when they couldn't reach the data centres, so they did, and the rest of the internet could no longer find Facebook, Instagram or WhatsApp. Because Facebook's internal tools depended on the same systems, fixing it took hours.
How to protect yourself:
- Use a reliable managed DNS provider, and for critical services consider two independent providers serving the same zone, so one provider's outage doesn't take you down.
- Keep reasonable TTLs. Very short TTLs mean resolvers ask more often, so an outage of your DNS hurts users sooner. A balance like 5 minutes to an hour, depending on how fast you need to change things, is common.
- Don't let your recovery tools depend on the thing that's broken. Keep a way to reach your systems (and a list of IP addresses) that doesn't need your own DNS.
- Watch it: monitor resolution of your main names from several places in the world (Chapter 30).
Memory code: "If DNS is down, you're down, even when everything is up."