EXERCISE
1Modern applications use load balancers at multiple levels. Understanding production patterns helps you design better systems.
Save
Enterprise applications use load balancers at multiple levels.
Example: E-Commerce Application
Internet
↓
[Global Load Balancer] - Routes by geography
↓
[Regional Load Balancer] - Routes to app servers
↓
[App Servers] - Business logic
↓
[Database Load Balancer] - Routes to read replicas
↓
[Database Servers]
Layer 1: Geographic distribution (US, Europe, Asia)
Layer 2: Application tier
Layer 3: tier load balancing
Each layer optimizes for different goals.
Application Load Balancer (Layer 7):
Understands HTTP. Can route based on URL path, headers, .
Example:
/api/products → Product Service/api/users → User Service/api/orders → Order ServiceSame load balancer, different backend services based on URL.
Network Load Balancer (Layer 4):
Routes based on IP and port. Extremely fast. No HTTP inspection.
Best for raw performance. Used for TCP/UDP traffic like databases, gaming, video streaming.
Global Load Balancer (DNS-based):
Routes based on client location. Directs users to nearest .
Example: Netflix uses this to route users to closest edge location.
AWS Elastic Load Balancer: Fully managed. Auto-scales. Integrates with EC2, ECS, Lambda.
Google Cloud Load Balancing: Global load balancing built-in. Routes across regions automatically.
Azure Load Balancer: Integrated with Azure services. Health included.
Key advantage: Managed services. No maintenance, automatic scaling, built-in monitoring.
Question: If load balancer handles all traffic, what happens when it fails?
Answer: Load balancers themselves are highly available.
How:
Cloud providers handle this automatically. AWS ELB runs across multiple zones. One zone fails? Others take over instantly.
Latency: Load balancer adds minimal latency (typically 1-5ms). Negligible compared to network round-trip time.
Throughput: Modern load balancers handle millions of requests per second.
SSL Termination: Load balancers can handle HTTPS encryption/decryption, offloading this work from backend servers.
Load balancers provide valuable metrics:
Request rate: Requests per second to each backend
Error rate: Failed requests percentage
Latency: Response time distribution
Health status: Which servers are healthy/unhealthy
These metrics help identify issues before users notice.
Example: Sudden spike in errors to 2? Investigate immediately. Maybe disk is full, memory leak, or bad deployment.
Health check endpoints: Create dedicated /health endpoints. Should check:
Timeout settings: Balance between patience and responsiveness. 30-second timeout is common.
Connection limits: Prevent one server from accepting too many connections.
Session stickiness: Enable only when necessary. Stateless applications do not need it.
Cloud load balancers: Pay for capacity and data transferred. Typically $20-50/month for small applications. Scales with usage.
DIY load balancers (, HAProxy): Free software, but you manage infrastructure, updates, high availability.
Most teams choose managed services: The operational burden of running load balancers yourself is not worth the cost savings.
Load balancers transformed from specialized infrastructure to essential commodity. Every production application uses them.
They enable:
Understanding load balancers deeply is fundamental to designing modern systems.