Domain Name System (DNS)¶
What it does¶
DNS translates a domain name (e.g., www.example.com) into an IP address.
How it works¶
- DNS is hierarchical, with a few authoritative servers at the top level.
- Your router or ISP tells you which DNS server(s) to contact for lookups.
-
Lower-level DNS servers cache mappings, which can become stale due to propagation delays.
-
Results can also be cached by your browser/OS for a period set by the time-to-live (TTL).
Common record types¶
| Record | Meaning |
|---|---|
| NS (name server) | Specifies the DNS servers for your domain/subdomain. |
| MX (mail exchange) | Specifies the mail servers for accepting messages. |
| A (address) | Points a name to an IP address. |
| CNAME (canonical) | Points a name to another name (or CNAME, or an A record). |
Managed DNS and routing methods¶
Managed DNS services include Cloudflare and AWS Route 53. They can route traffic using:
-
Weighted round robin — avoid servers under maintenance, balance between cluster sizes, A/B testing.
-
Latency-based — route to the nearest/fastest region.
- Geolocation-based — route based on user location.
Disadvantages of DNS¶
- A DNS lookup adds a slight delay (mitigated by caching).
-
DNS server management is complex and generally managed by governments, ISPs, and large companies.
-
DNS is a target for DDoS attacks (e.g., the 2016 Dyn attack took down sites like Twitter for users who didn't know the IP directly).
Key takeaways¶
-
DNS is effectively a giant, hierarchical, cached key-value store mapping names to addresses.
-
TTL governs freshness vs. caching benefit — a longer TTL reduces lookups but slows propagation of changes.
-
It's an example of eventual consistency in the wild.
Common Interview Questions¶
Design a CDN like Cloudflare (global routing)
Why it's asked here: a CDN's global routing is fundamentally a DNS routing problem.
Key points to discuss:
- Use geo/latency-based DNS to route users to the nearest PoP.
- A/AAAA, CNAME, and NS records; the TTL trade-off (fast propagation vs caching).
- Anycast to route one IP to the nearest node.
- How DNS caching layers (browser, OS, resolver) affect staleness.
flowchart LR
U[User] --> R[Resolver]
R --> A[Authoritative DNS]
A -->|geo / latency| E1[Edge POP 1]
A -->|geo / latency| E2[Edge POP 2]
U --> E1
Design a globally available multi-region service
Why it's asked here: routing traffic across regions relies on DNS.
Key points to discuss:
- Weighted round-robin, latency-based, and failover routing policies.
- Health checks to stop sending traffic to unhealthy regions.
- DNS TTL and why failover can be slow (clients cache old IPs).
- DNS as a control plane vs data plane trade-off.
flowchart LR
U[User] --> D[DNS]
D -->|weighted / latency| R1[Region A]
D -->|health check| R2[Region B]
R1 <-->|replication| R2