Load Balancing
Algorithms, health checks, and capacity planning
Not Started
Loading...
⚡ Quick Decision
Choose Layer 4 When:
- • Need maximum throughput (>1M RPS)
- • TCP/UDP protocols
- • Minimal latency overhead
Choose Layer 7 When:
- • Need content-based routing
- • SSL termination required
- • A/B testing & canary deploys
Algorithm Choice:
- • Round Robin: Uniform workloads
- • Least Connections: Long-lived requests
- • IP Hash: Session affinity
💡 For implementation guides and code examples: See our comprehensive Proxies & Load Balancing Technology Deep Dive
Layer 4 vs Layer 7 Decision
Layer choice impacts throughput, latency, and features. Choose based on your primary constraint.
🏎️ Layer 4 (Transport)
Throughput: 2M+ RPS (HAProxy)
Latency: +0.1ms overhead
Memory: 4KB per connection
Best for: High-performance TCP/UDP
🌐 Layer 7 (Application)
Throughput: 200K RPS (NGINX)
Latency: +2ms overhead
Memory: 64KB per connection
Best for: HTTP routing & SSL termination
Algorithm Selection Matrix
Choose your load balancing algorithm based on traffic patterns and session requirements.
Round RobinEqual capacity servers
✓ Advantage:
Simple, fair distribution
✗ Trade-off:
Ignores server load
Weighted Round RobinDifferent capacity servers
✓ Advantage:
Accounts for server specs
✗ Trade-off:
Static weights
Least ConnectionsLong-lived connections
✓ Advantage:
Dynamic load awareness
✗ Trade-off:
Connection ≠ load
IP HashSession affinity needed
✓ Advantage:
Sticky sessions
✗ Trade-off:
Uneven distribution
Least Response TimeLatency-sensitive apps
✓ Advantage:
Optimizes for speed
✗ Trade-off:
More overhead
Health Check Strategy
Health Check Types
TCP Check (Basic)
• Latency: ~1ms
• Use for: Simple port connectivity
HTTP Check (Recommended)
• Latency: ~10ms
• Use for: Application health
Configuration Guidelines
Check interval:1-5 seconds
Timeout:1-2 seconds
Failure threshold:3 consecutive
Success threshold:2 consecutive
⚠️ Critical Health Check Rules
- • Exclude health endpoints from rate limiting
- • Health checks should not modify application state
- • Use separate health check pools for dependencies
- • Monitor health check response times
Real-World Performance
Typical throughput numbers for production load balancers.
HAProxy (L4)
2M RPSHigh-performance TCP
NGINX (L7)
200K RPSHTTP with SSL termination
AWS ALB (L7)
100K RPSManaged HTTP load balancer
Production Deployment Checklist
🔧 Essential Setup
- □Deploy load balancers in HA pairs
- □Configure aggressive health check timeouts
- □Set up monitoring for backend health
- □Enable connection draining for deployments
⚡ Performance Tuning
- □Tune TCP buffer sizes for high throughput
- □Enable connection pooling to backends
- □Configure keep-alive for HTTP/1.1
- □Monitor CPU and memory utilization
⚠️ Avoid Single Points of Failure
Always deploy load balancers in pairs with keepalived or equivalent failover. A single load balancer failure should never take down your entire application.
📝 Test Your Knowledge
6 questions • Progress: 0/6