Module 8 - Networking and APIs

DNS Deep Dive

How the internet's phone book works-and why it matters for system design.

1The Phone Book Analogy

Simple Analogy
Before smartphones, you'd look up a business in the Yellow Pages to find their phone number. DNS is the internet's phone book-you give it a name (google.com), and it gives you a number (142.250.80.14) so you can connect.

DNS (Domain Name System) translates human-readable domain names into IP addresses. It's a distributed, hierarchical database that powers every internet request.

2DNS Resolution Flow

1
Browser Cache
Check if we resolved this recently. TTL-based expiry.
Hit: done. Miss: continue.
2
OS Cache
Operating system maintains its own cache.
Hit: done. Miss: continue.
3
Recursive Resolver
Your ISP's DNS server. Does the heavy lifting.
Checks its cache, or queries up the chain.
4
Root Nameserver
Knows where to find .com, .org, .io servers.
Returns: 'Ask the .com server'
5
TLD Nameserver
Top-Level Domain server (.com, .org).
Returns: 'Ask Google's nameserver'
6
Authoritative Nameserver
Google's server knows google.com's IP.
Returns: 142.250.80.14

Full resolution takes 4 round trips. Caching at each level dramatically reduces this for popular domains.

3DNS Record Types

TypePurposeExample
ADomain to IPv4example.com → 93.184.216.34
AAAADomain to IPv6example.com → 2606:2800:220:1:...
CNAMEAlias to another domainwww.example.com → example.com
MXMail serverexample.com → mail.example.com
TXTText data (verification)SPF, DKIM, domain verification
NSNameserver delegationexample.com → ns1.provider.com

4TTL and Caching

300s (5 min)

Dynamic IPs, failover

More queries, faster propagation

3600s (1 hour)

Standard websites

Balanced caching and updates

86400s (1 day)

Stable services

Fewer queries, slow propagation

604800s (1 week)

Very stable infrastructure

Maximum caching, slowest updates

Migration Tip

Before migrating servers, lower TTL to 5 minutes days in advance. After migration, you can raise it again.

5DNS for Load Balancing

Round Robin

Return different IPs in rotation. Simple but no health awareness.

First query: 10.0.0.1, Second: 10.0.0.2, Third: 10.0.0.3

Weighted Round Robin

Higher weight = more traffic. For heterogeneous servers.

Server A (weight 3) gets 3x traffic of Server B (weight 1)

Geolocation

Return closest server based on client location.

US client → us-east.example.com, EU client → eu-west.example.com

Latency-based

Route to lowest latency datacenter.

AWS Route 53 measures latency to each region

6Common Issues

DNS Propagation Delay

After changing DNS, old records cached worldwide. Takes up to 48 hours for full propagation.

Fix: Lower TTL before changes, wait, then make changes.

DNS Cache Poisoning

Attacker injects fake records into resolver cache. Users redirected to malicious sites.

Fix: Use DNSSEC. Validate responses.

Single Point of Failure

All traffic depends on DNS. If DNS is down, nothing works.

Fix: Multiple nameservers, different providers.

7Key Takeaways

1DNS translates domains to IPs through a hierarchical system
2Resolution: Browser → OS → Resolver → Root → TLD → Authoritative
3TTL controls caching duration. Lower = faster updates, more queries
4A (IPv4), CNAME (alias), MX (mail) are key record types
5DNS-based load balancing: round robin, geo, latency-based

?Quiz

1. You're migrating to new servers. What should you do first?

2. CNAME record is used for: