Skip to main content

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

OptionDescriptionDefault
pathHealth check endpoint/health
intervalCheck interval (ms)30000
timeoutRequest timeout (ms)5000
unhealthyThresholdFailures before marking unhealthy3
healthyThresholdSuccesses before marking healthy2

Failover

When a backend becomes unhealthy:

  1. It's removed from the rotation
  2. Traffic is redistributed to healthy backends
  3. Health checks continue in the background
  4. 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" }
]
}