Load Balancing
Distribute traffic across multiple backend servers with intelligent load balancing strategies.
Strategies
Round-Robin (Default)
Distributes requests evenly across all healthy backends.
{
"loadBalancing": {
"strategy": "round-robin"
},
"backends": [
{ "url": "http://backend1:3000" },
{ "url": "http://backend2:3000" },
{ "url": "http://backend3:3000" }
]
}
Weighted
Distributes requests based on weight. Perfect for canary deployments and A/B testing.
{
"loadBalancing": {
"strategy": "weighted"
},
"backends": [
{ "url": "http://stable:3000", "weight": 90 },
{ "url": "http://canary:3000", "weight": 10 }
]
}
IP-Hash
Routes requests from the same IP to the same backend. Provides session affinity.
{
"loadBalancing": {
"strategy": "ip-hash"
},
"backends": [
{ "url": "http://backend1:3000" },
{ "url": "http://backend2:3000" }
]
}
Least-Connections
Routes to the backend with the fewest active connections. Best for variable request durations.
{
"loadBalancing": {
"strategy": "least-connections"
},
"backends": [
{ "url": "http://backend1:3000" },
{ "url": "http://backend2:3000" }
]
}
Health Checks
Monitor backend health automatically:
{
"backends": [
{
"url": "http://backend1:3000",
"healthCheck": {
"enabled": true,
"path": "/health",
"interval": 30000,
"timeout": 5000,
"unhealthyThreshold": 3,
"healthyThreshold": 2
}
}
]
}
Health Check Options
| Option | Description | Default |
|---|---|---|
path | Health check endpoint | /health |
interval | Check interval (ms) | 30000 |
timeout | Request timeout (ms) | 5000 |
unhealthyThreshold | Failures before marking unhealthy | 3 |
healthyThreshold | Successes before marking healthy | 2 |
Failover
When a backend becomes unhealthy:
- It's removed from the rotation
- Traffic is redistributed to healthy backends
- Health checks continue in the background
- Backend is restored when healthy again
Use Cases
Blue-Green Deployment
// Switch traffic from blue to green
{
"loadBalancing": { "strategy": "weighted" },
"backends": [
{ "url": "http://blue:3000", "weight": 0 },
{ "url": "http://green:3000", "weight": 100 }
]
}
Canary Release
// Gradually increase canary traffic
{
"loadBalancing": { "strategy": "weighted" },
"backends": [
{ "url": "http://stable:3000", "weight": 95 },
{ "url": "http://canary:3000", "weight": 5 }
]
}
Geographic Distribution
// Route based on backend location
{
"loadBalancing": { "strategy": "round-robin" },
"backends": [
{ "url": "http://us-east:3000" },
{ "url": "http://us-west:3000" },
{ "url": "http://eu-west:3000" }
]
}