categories.system-design Intermediate
Load Balancing Strategies: Algorithms and L4 vs L7 Differences
Load Balancing Strategies
Common Algorithms
| Algorithm | Principle | Best For |
|---|---|---|
| Round Robin | Distribute in turn | Servers with similar capacity |
| Weighted Round Robin | Distribute by weight | Servers with different specs |
| Least Connections | Route to server with fewest active connections | Long-lived connections |
| IP Hash | Fixed routing based on client IP | Session sticky requirements |
| Random | Random assignment | Simple use cases |
L4 vs L7 Load Balancing
L4 (Transport Layer)
- Based on TCP/UDP; doesn't inspect application content
- Faster performance
- Examples: AWS NLB, HAProxy in TCP mode
L7 (Application Layer)
- Based on HTTP/HTTPS; can inspect URL, headers, cookies
- Supports URL-based routing, SSL termination, A/B testing
- Examples: Nginx, AWS ALB, Kong
Health Checks
Load balancer periodically probes backend services and removes unhealthy nodes:
- Passive: Based on observed failure rate
- Active: Regularly sends dedicated health check requests
Interview bonus: GSLB (Global Server Load Balancing) uses DNS to route users to the nearest data center—the solution for geographic load balancing.
✦ AI Mock Interview
Type your answer and get instant AI feedback
Sign in to use AI scoring
