Domain Name System (DNS)
Scenario
Computers route traffic using numeric IP addresses, but humans are terrible at memorizing numbers. If we had to type '142.250.190.46' to visit Google, the internet would be unusable.
How does your device translate a domain name into an IP address in milliseconds?
Mental model
DNS is the phonebook of the internet.
You look up a person by their name (google.com) to find their phone number (142.250.190.46) so your device knows exactly who to call.
Explanation
The Domain Name System (DNS) is a hierarchical and decentralized naming system for computers connected to the internet. Its primary purpose is to translate memorable human-friendly domain names (like 'github.com') into machine-friendly IP addresses. Because there are billions of devices, no single server can hold all the mappings. Instead, DNS distributes this directory across thousands of servers worldwide.
When you type a URL into your browser, the first step is checking your local cache—your computer might already remember the IP address from a recent visit. If not, your computer asks a DNS Resolver, typically provided by your Internet Service Provider (ISP) or a public service like Google's 8.8.8.8. The Resolver's job is to hunt down the IP address on your behalf, navigating the DNS hierarchy.
If the Resolver doesn't have the answer cached, it starts at the top by querying a Root Name Server. The Root server doesn't know the exact IP, but it knows which Top-Level Domain (TLD) server handles '.com' or '.org' extensions. The Resolver then asks the TLD server, which in turn directs the Resolver to the Authoritative Name Server for that specific domain (e.g., the server specifically managing 'github.com').
The Authoritative Name Server is the final stop. It holds the official DNS records for the domain. It returns the exact IP address to the Resolver, which caches the result to speed up future requests and finally hands the IP back to your browser. Your browser can now establish a direct connection with the web server.
DNS relies heavily on different types of records. An 'A' record maps a domain directly to an IPv4 address, while an 'AAAA' record maps it to an IPv6 address. A 'CNAME' record aliases one domain name to another, acting like a redirect. By caching responses at every level (browser, OS, Resolver), DNS remains incredibly fast despite the complex global lookup process required for a cache miss.
Key points
- A Record: Maps a domain name to an IPv4 address (e.g., 93.184.216.34).
- AAAA Record: Maps a domain name to an IPv6 address.
- CNAME Record: Canonical Name record. Maps an alias domain name to the true (canonical) domain name.
- MX Record: Mail Exchange record. Directs email to a mail server.
Common mistakes
- Thinking DNS is a single central server: DNS is a globally distributed, hierarchical database. A central server would be a massive single point of failure and bottleneck.
- Confusing CNAME and A records: An A record points a name directly to an IP address. A CNAME points a name to another name (e.g., www.example.com -> example.com).
Glossary
- Domain Name System
- The internet's phonebook that automatically translates human-readable website names into the computer-friendly IP addresses needed to load them.
- decentralized
- A system design where power and information are spread out across many different computers worldwide, rather than being controlled by a single central server.
- local cache
- A temporary, super-fast storage area on your computer that remembers recently visited website IP addresses so you don't have to look them up again.
Recall questions
- What is the role of a DNS Resolver?
- What type of DNS record would you use to point a domain to an IPv6 address?
- Why is caching critical to the DNS architecture?
Questions & answers
Which DNS server is at the top of the DNS hierarchy and provides the IP address of TLD servers?
Root Name Server
Approach: The DNS lookup sequence goes: Resolver -> Root -> TLD -> Authoritative. The Root server is the starting point that knows where the .com, .org, etc., servers live.
If you want the domain 'blog.mysite.com' to point to exactly the same IP address as 'mysite.com', which DNS record type is best practice to use?
CNAME Record
Approach: A CNAME allows you to alias 'blog.mysite.com' to 'mysite.com'. If 'mysite.com' changes its IP (its A record), 'blog.mysite.com' will automatically route to the new IP without needing an update.