Problem statement
Suppose you have four backend servers: A, B, C, and D. How should the load balancer decide where to send each incoming request so traffic is distributed evenly and services remain responsive?Round-robin (simple pointer)
Round-robin is the simplest approach. The balancer keeps an ordered list of servers and a single index that points to the next server. For each request it forwards the request to the server at the current index and then increments the index, wrapping back to zero at the end. Example state:- Extremely simple to implement
- Predictable distribution when requests are uniform
- Blind to per-request work or latency. If some requests are long-running (e.g., payment processing) a server can be overloaded while others idle.
Least-connections strategy
Least-connections is more adaptive: send each new request to the server currently handling the fewest active connections or requests. The balancer tracks an active count for each backend; it increments when it assigns a request and decrements when the request completes. Important nuance: with multiplexed protocols (HTTP/2, gRPC) a single connection may carry many concurrent requests. Some balancers therefore count active requests instead of connections, or combine counts with metrics like CPU usage and request latency.When using HTTP/2 or similar multiplexed transports, prefer metrics that reflect concurrent work (active requests, CPU, latency) rather than raw TCP connection counts.

- Adapts to heterogeneous request durations
- Helps prevent long-running requests from concentrating on a single server
- Requires accurate accounting of active work
- Slightly more complexity than round-robin
Health checks (detecting dead backends)
Detecting and removing unhealthy backends is essential to avoid directing traffic to dead or degraded servers. Common approaches:-
Passive health checks:
- The balancer observes user traffic. If requests fail or time out to a backend, the balancer temporarily stops sending new requests to it and probes later.
- Pro: No extra probes. Con: Detection occurs only after real requests fail.
-
Active health checks:
- The balancer periodically sends lightweight probe requests (for example, every 2 seconds). If a backend fails several probes in a row (commonly 3), it is marked down and removed from rotation.
- Pro: Faster detection. Con: Extra probe traffic.
- Probe endpoint should be lightweight and representative of app health (for example,
GET /healthz). - Balance sensitivity and noise (probe interval, failure threshold) to avoid false positives during transient spikes.
NGINX example
NGINX (open-source) uses round-robin by default. Switching to least-connections requires a single directive in theupstream block:
Active health checks (and advanced features like slow-start/warmup) are available in NGINX Plus. The open-source NGINX supports passive checks and several basic load-balancing modes.
Warm-up / slow-start after a backend returns
When a backend recovers, it typically has zero active connections. A plain least-connections balancer might immediately send many new requests to it, which can overwhelm caches, warmed-up services, or background initialization logic. To avoid this, use a warm-up or “slow-start” behavior: gradually increase the share of traffic to a returning backend over a configured interval so it can build caches and stabilize.
Quick comparison
Additional considerations
- Sticky sessions: If your app stores session state locally, sticky sessions (cookie-based or IP-hash) ensure subsequent requests hit the same backend. Use with caution — it reduces the balancer’s flexibility.
Relying on sticky sessions can make scaling and failover harder. Prefer stateless services or externalize session state (Redis, database) where possible.
- Weights: Use when backends have different capacity (e.g., larger machines get higher weights).
- Observability: Track active requests, request duration histograms, CPU, memory, and error rates to make informed balancing decisions.
- Autoscaling integration: Combine health checks and metrics with autoscaling to add/remove capacity automatically.
- Use proven software or cloud load balancers rather than implementing complex logic from scratch (NGINX, HAProxy, Envoy, AWS/Cloud Load Balancers).
Summary
- Round-robin is simple but blind to server load and request duration.
- Least-connections routes to the backend with the fewest active connections or requests and adapts to heterogeneous request costs.
- Health checks can be passive (observe failures) or active (periodic probes); active checks detect failures faster.
- Warm-up / slow-start prevents sudden traffic spikes to recovering servers.
- Prefer mature load balancer implementations and externalized session/state management rather than building custom balancers from scratch.