Load balancers distribute traffic across multiple servers.
Layer (Transport):
- Routes based on IP and port
- Faster, less overhead
- Can't inspect HTTP content
- Examples: AWS NLB, HAProxy in TCP mode
Layer (Application):
- Routes based on HTTP content (path, headers, cookies)
- Can terminate TLS
- More flexible routing rules
- Examples: AWS ALB, Nginx, HAProxy in HTTP mode
Algorithms:
- Round robin: Rotate through servers
- Least connections: Send to server with fewest active connections
- IP hash: Same client IP goes to same server
Interview question: "When would you use L4 vs L7 load balancing?"