DNS Records, TTL, Caching and Routing
Overview
A domain's DNS data is stored as small records of different types. How long those answers are cached (the TTL) decides how quickly changes take effect, and clever DNS setups can even send different users to different servers.
Detailed Notes
What is a DNS record
A DNS record is one entry in a domain's data, saying "this name means this". The collection of records for a domain is its zone. The common types:
- A: name to an IPv4 address, e.g.
www.example.com -> 203.0.113.25. - AAAA: name to an IPv6 address (the newer, longer address format), e.g.
www -> 2001:db8::1. - CNAME: name to another name (an alias), e.g.
blog.example.com -> example.hosting.com. - MX: where to deliver the domain's email, e.g.
example.com -> mail.provider.com. - TXT: free text, often used to prove domain ownership or for email security.
- NS: which servers are authoritative for the domain.
The problem it solves
One domain needs to do many jobs: point the website at one machine, email at another, and blog at a third-party service. Separate record types let each job be configured independently.
Caching solves a different problem: asking the full root-TLD-authoritative chain for every page load would be slow and would overload the authoritative servers. So answers are remembered. But remembering creates a new problem: how long is an answer safe to remember?
How it works
TTL (Time To Live) is a number of seconds attached to each record that tells resolvers how long they may cache it. With a TTL of 300, a resolver reuses the answer for five minutes before asking again.
- Long TTL (hours/days): fewer lookups, faster for users, lower load. But changes spread slowly.
- Short TTL (30-60 s): changes take effect fast. But more lookups and a bit more delay.
Caches exist at several levels (browser, operating system, resolver), so a change is never instant everywhere. A common trick: lower the TTL a day before a planned move, switch the record, then raise it again.
Routing with DNS. Since the authoritative server decides the answer, it can give different answers to different people:
- Round robin: one name has several A records; answers rotate so traffic spreads across several servers.
- Geo or latency routing: users in Europe get the IP of the European data centre, users in Asia get the Asian one, so each is served from nearby.
- Health-check failover: the DNS service watches the servers. If the primary stops responding, it stops handing out its IP and returns the backup's IP instead.
A simple example
You own example.com:
Arecord:example.com -> 203.0.113.25(the website).CNAME:www -> example.com(so both names work).MX: email goes to your mail provider.
You move to a new server with IP 198.51.100.9. You edit the A record. Users whose resolver cached the old answer (TTL 3600) keep going to the old server for up to an hour. Users after that get the new one.
System design example
A streaming company runs servers in two regions. Its DNS uses latency routing plus health checks: each user gets the nearest region, and if one region fails, DNS stops returning it and everyone goes to the other.
Limits to remember:
- DNS failover is slow, because cached answers stay in use until the TTL expires (some resolvers even ignore short TTLs).
- DNS does not know how busy each server is; it only rotates or picks by location.
- A
CNAMEcannot be placed at the bare domain (example.com) in standard DNS, so providers offer special alias records.
So DNS-based steering is great for coarse, global traffic direction. Finer, faster distribution inside a region uses other tools (covered later).
Summary
- Records (A, AAAA, CNAME, MX, TXT, NS) each describe one fact about a domain.
- TTL controls how long answers are cached: long means fast and light, short means quick changes.
- Lower the TTL before a planned change.
- DNS can steer users by rotation, location or health, but failover is only as fast as the TTL.
Architecture Diagram
DNS returns the closest healthy region for each user.
- 1A user looks up the site name.
- 2DNS checks which regions are healthy.
- 3It returns the IP of the closest healthy region.
- 4The user connects to that region.
Common Interview Questions
Chapter quiz
DNS · 5 questions
1.What does a recursive resolver do?
2.Which server holds the real DNS records for example.com?
3.You change an A record but some users still reach the old server. Why?
4.Which record type tells other servers where to deliver email for a domain?
5.What is a good use of DNS routing in system design?
0 of 5 answered
Finished this lesson?
0 of 91 lessons done · 0% of the course

