DNS (Domain Name System)
Context & Purpose
DNS is the decentralized phonebook of the internet. It translates human-readable hostnames (e.g., google.com) into machine-readable IP addresses (e.g., 142.250.190.46). Without it, we would have to memorize IPs.
Mechanism / Architecture
DNS is a Hierarchical Distributed Database.
Key Concepts
- Recursion: The User asks the Resolver to "do the work". The Resolver performs the iterative steps.
- Caching: Every step (Browser, OS, Router, ISP) caches the result for a duration defined by TTL (Time To Live). Low TTL = specific traffic control; High TTL = less load.
- Hierarchy:
- Root (.): Managed by ICANN (13 logical server clusters).
- TLD (.com, .org): Managed by Registries (e.g., Verisign).
- Authoritative: The actual server holding the records (e.g., Route53, Cloudflare).
Analysis & Trade-offs
Pros
- Decentralization: No single point of failure for the entire internet.
- Scalability: Heavy caching at every layer absorbs massive traffic.
Cons
- Propagation Delay: Changes to records take time to propagate due to caching (TTL).
- Security: Vulnerable to spoofing (fixed by DNSSEC) and amplification attacks.
Real-world Usage
Common Record Types
| Record | Purpose | Example |
|---|---|---|
| A | Hostname -> IPv4 | example.com -> 1.2.3.4 |
| AAAA | Hostname -> IPv6 | example.com -> 2001:db8::1 |
| CNAME | Hostname -> Hostname (Alias) | www.example.com -> example.com |
| MX | Mail Server | example.com -> mail.google.com |
| NS | Nameserver Delegation | example.com -> ns1.aws.com |
CNAME limitation
Critical: You generally cannot put a CNAME at the "Root" (apex) of a domain (e.g.,
example.com). You can only use it for subdomains (www.example.com). Cloud providers created "Alias" or "Flattening" records to bypass this restriction.
Interview Check
- What happens when you type a URL into the browser?
- (DNS step): Browser checks cache -> OS cache -> ISP Resolver -> Root -> TLD -> Auth NS.
- Why use a CNAME vs an A Record?
- Use CNAME when you want to alias to another service (like an ELB) whose IP might change. Use A Record when you control the static IP.