4. DNS
4.5 What is a TTL, and why does DNS cache so much?
In your phone's contacts: Imagine every saved number came with "valid until Friday". Until Friday you just dial it. After Friday you check again. A long validity means fewer checks but a slow update when someone changes number; a short one means fresh numbers but lots of checking.
In the system: Every record has a TTL (time to live) in seconds. Any resolver or device that caches the answer may reuse it for that long without asking again.
| TTL | Good for | Trade-off |
|---|---|---|
| 60 to 300 seconds | Records you may need to change fast (failover, migrations) | More queries to your name servers; a little more lookup time for users |
| 1 to 24 hours | Records that rarely change | Changes take that long to reach everyone |
How many queries reach your name servers? Roughly one per resolver per TTL, not one per user. If 10,000 resolvers around the world serve your users and the TTL is 300 seconds, that's about 33 queries a second to your authoritative servers, however many millions of users there are. Caching is why DNS can serve the entire internet.
Resolvers also cache "this name doesn't exist" answers (called negative caching, NXDOMAIN), so a typo or a bot asking for random names doesn't hit the authoritative servers every time.
Memory code: "TTL is the use-by date on a saved answer." Short TTL: fresh but busy. Long TTL: calm but slow to change.