Chapter 5: DNS, IP, TCP/UDP — The Network Foundation
DNS: The Internet's Phone Book
User types: www.example.com
│
▼
Browser cache → OS cache → Router cache → ISP DNS
│ (miss at all levels)
▼
Root DNS (.com) → TLD DNS (example.com) → Authoritative DNS
│
▼
Returns: 93.184.216.34 (IP address)
│
▼
Browser connects to 93.184.216.34:443
DNS in System Design
- DNS load balancing: return different IPs for same domain (round-robin)
- Geographic routing: return nearest server's IP based on client location
- Failover: health-check IPs, remove unhealthy ones from DNS
- TTL: how long clients cache the IP (trade-off: fast failover vs DNS load)
TCP vs UDP
| Aspect | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (3-way handshake) | Connectionless |
| Reliability | Guaranteed delivery, ordering | Best-effort, may lose packets |
| Overhead | Higher (headers, ACKs, retransmits) | Lower (minimal headers) |
| Use cases | HTTP, gRPC, database connections | DNS, video streaming, gaming, VoIP |
TCP Connection Lifecycle
// 3-way handshake (connection setup): ~1 RTT
Client → SYN → Server
Client ← SYN+ACK ← Server
Client → ACK → Server
// Now connected. Add TLS handshake: +1-2 RTT
// Total setup: 2-3 RTT before first byte of data
// At 40ms RTT (US coast-to-coast): 80-120ms just to connect!
// → This is why connection reuse (keep-alive, HTTP/2) matters
Key Networking Concepts for System Design
- Bandwidth: max data rate (pipe width). Rarely the bottleneck.
- Latency: time for one round trip (pipe length). Often the bottleneck.
- Throughput: actual data rate achieved. Limited by both.
- Connection pooling: reuse TCP connections to avoid handshake overhead
- Keep-alive: don't close connections between requests
💡 Latency Dominates
For most web services, latency (not bandwidth) is the bottleneck. A 1KB response over a 1Gbps link takes 0.008ms to transmit but 40ms for the round trip. Reducing round trips (caching, CDN, connection reuse) matters more than increasing bandwidth.
Key Takeaways
- DNS translates names to IPs — used for load balancing and geo-routing
- TCP: reliable, ordered — used for HTTP/gRPC/databases
- UDP: fast, unreliable — used for DNS, streaming, real-time
- Connection setup costs 2-3 RTTs — reuse connections
- Latency (not bandwidth) is usually the bottleneck