You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Load balancing is the process of distributing network traffic across multiple servers to ensure no single server is overwhelmed. It improves availability, reliability, and performance.
2. Types of Load Balancers
Type
Layer
Description
L4 (Transport)
TCP/UDP
Routes based on IP and port
L7 (Application)
HTTP
Routes based on content, headers, URL
L4 vs L7 Load Balancers
Feature
L4
L7
Speed
Faster
Slightly slower
Intelligence
Basic
Content-aware
SSL Termination
Usually no
Yes
URL Routing
No
Yes
WebSocket Support
Limited
Full
3. Load Balancing Algorithms
Static Algorithms
Algorithm
Description
Use Case
Round Robin
Distribute sequentially
Equal capacity servers
Weighted Round Robin
Consider server weights
Unequal capacity
IP Hash
Hash client IP to server
Session persistence
Dynamic Algorithms
Algorithm
Description
Use Case
Least Connections
Route to server with fewest connections
Long-lived connections
Weighted Least Connections
Consider weights + connections
Variable capacity
Least Response Time
Route to fastest responding
Latency-sensitive apps
Resource Based
Based on server resources (CPU, RAM)
Heterogeneous servers
4. Health Checks
Load balancers continuously check server health to avoid routing to failed servers.
Health Check Types:
1. TCP Check - Can establish connection?
2. HTTP Check - Does /health return 200?
3. Custom Script - Run specific health validation
Parameter
Typical Value
Interval
5-30 seconds
Timeout
2-5 seconds
Unhealthy Threshold
2-3 failures
Healthy Threshold
2-3 successes
5. Session Persistence (Sticky Sessions)
Ensure requests from the same client go to the same server.
Methods
Cookie-based: Insert cookie with server ID
IP-based: Hash client IP
URL-based: Encode session in URL
Pros
Cons
Session data locality
Uneven load distribution
Simpler app design
Server failure loses sessions
Cache efficiency
Scaling challenges
6. Reverse Proxy
A reverse proxy sits between clients and servers, forwarding requests to backend servers.
Client → Reverse Proxy → Server 1
→ Server 2
→ Server 3