Load Balancing
Master L4 vs L7 load balancers, load balancing algorithms (Round-Robin, Least Connections, IP Hash), health checks, sticky sessions, and real-world tools like NGINX and AWS ALB.
Master L4 vs L7 load balancers, load balancing algorithms (Round-Robin, Least Connections, IP Hash), health checks, sticky sessions, and real-world tools like NGINX and AWS ALB. This hands-on tutorial focuses on practical implementation of load balancing concepts.
Load Balancing
A load balancer distributes incoming network traffic across multiple servers to ensure no single server becomes a bottleneck. It is the entry point to any scalable system.

L4 vs L7 Load Balancers
Load balancers operate at different layers of the OSI model, with different capabilities and performance characteristics:
| Feature | L4 (Network LB) | L7 (Application LB) |
|---|---|---|
| Operates on | TCP/UDP packets | HTTP/HTTPS content |
| Routing based on | IP + Port | URL, headers, cookies, content |
| SSL Termination | ❌ No (passes through) | ✅ Yes (handles TLS) |
| Content routing | ❌ No | ✅ Yes (path-based, host-based) |
| Performance | ⚡ Faster (less processing) | Slightly slower |
| Use case | Raw TCP, UDP, gaming, DNS | HTTP APIs, web apps |
| AWS product | NLB (Network Load Balancer) | ALB (Application Load Balancer) |
Load Balancing Algorithms
Health Checks
A load balancer must continuously monitor backend servers and remove unhealthy ones from rotation.
[!TIP] Implement three types of health endpoints in your services:
/health/live— Is the process alive? (Kubernetes liveness probe)/health/ready— Is the service ready to receive traffic? (Kubernetes readiness probe)/health— Full health status including dependencies (DB, cache, etc.)
Quiz
Quiz
Question 1 of 2Which load balancing algorithm is best for WebSocket connections where some connections stay open for hours?
Official Resources
- NGINX Load Balancing Guide
- HAProxy Documentation
- AWS Elastic Load Balancing
- Consistent Hashing — Tom White (Original Paper)
Key Takeaways
✅ L4 LB operates at network layer — fast, but can only route by IP/port.
✅ L7 LB sees HTTP content — enables path routing, SSL termination, A/B testing.
✅ Round Robin is simplest; Least Connections is best for variable request durations.
✅ IP Hash creates sticky sessions — only use it for legacy stateful apps.
✅ Health checks automatically remove failed servers — configure active (ping) + passive (error rate) checks.
What's Next?
Load balancers distribute traffic, but we can reduce load entirely with caching.
Next: Caching Strategies — Redis, CDN, eviction policies, and how Netflix serves millions with a tiny database load.