Load Balancing Algorithms: A Decision Guide
Choose a load-balancing policy by backend health, capacity, request duration, queueing, and proxy behavior, with links to focused algorithm deep dives.
Load-balancing algorithms choose an eligible backend for a connection or request. The best starting point depends on backend capacity, request duration, queueing, and what the proxy can measure. This guide compares common policies and links to deeper articles on consistent hashing and benchmark methods.
Load Balancing Algorithms: A Decision Guide
A load-balancing policy chooses a backend for a connection or request. The right choice depends on what the proxy can observe and how work differs between backends. Round robin is a useful baseline when instances and requests are similar. A more reactive policy can help when connection duration or queue depth tracks actual work, but it can also follow stale or misleading metrics.
Start with the simplest policy that fits the workload. Then compare it under the same health, retry, and capacity settings you expect to use in production.
Choose a starting policy
| Workload | Starting point | Check before relying on it |
|---|---|---|
| Similar backends and short, similar requests | Round robin | It distributes assignments, not CPU or total work. |
| Backends have different but stable capacity | Weighted round robin | Set weights from measured capacity and revisit them after changes. |
| Connections last for different lengths of time | Least connections | It helps only when connection duration tracks backend work. |
| An HTTP proxy can observe outstanding requests | Least requests or power of two choices | Check whether the implementation counts active requests, queued work, or both. |
| A stable key should usually stay with one backend | Consistent hashing | Key popularity can still create a hot backend; membership changes need a defined policy. |
| Host capacity or workload changes over time | A resource-aware or adaptive policy | Verify that measurements are fresh, comparable, and available during failures. |
These names are not interchangeable across products. A policy called “least connections” may count open transport connections, while another product’s least-request policy may count active HTTP requests. HTTP/2 can carry many requests over one connection, so connection count may not represent request load. Read the proxy’s definition before treating its label as a guarantee.
For ring lookup, virtual nodes, sticky sessions, and bounded-load trade-offs, see Consistent Hashing for Load Balancing. For least-connections and two-choice behavior under a declared mixed-duration workload, see Load Balancing Algorithms: Workloads and Benchmarks.
What changes algorithm performance
The algorithm only sees the signal exposed by the proxy. Four details often matter more than the name of the policy:
Backend health and capacity
Selection should happen among eligible backends. A failed health check can remove an instance from rotation, but a passing check does not prove that users can complete important requests. A shallow check may confirm that a process answers while a required database or downstream service is failing. Define health checks for the failure modes the service can detect safely, and watch user-facing errors and latency as well.
Equal weights assume roughly equal capacity. If instances differ in CPU, memory, or current limits, round robin may send the same number of requests to servers that cannot do the same amount of work. Weighted routing can account for stable differences; changing capacity calls for fresh measurements and careful weight updates.
Request and connection duration
Round robin gives each backend a similar number of assignments over time. It does not account for one request taking milliseconds while another holds a connection for seconds. Least-connections can help when long connections represent more work. It can mislead when idle keep-alive connections remain open or when one multiplexed connection carries many concurrent requests.
Queues and metric freshness
A backend with few active connections may still have a long queue. A proxy that can see outstanding requests or queue depth may make a better choice for that workload. However, stale or delayed metrics can send several new requests to a backend that only appears idle. Check how often the signal updates and what happens when it is unavailable.
Proxy behavior
A Layer 4 balancer generally chooses a backend for a connection or flow. An HTTP Layer 7 proxy can inspect a request and choose at request granularity, subject to connection reuse and product behavior. Session affinity, health ejection, connection draining, and retries also affect where work lands. To follow an L4 connection and an L7 request through the system, see Load Balancing: Traffic Control for Modern Infrastructure.
Keep related controls separate
| Concern | Typical responsibility | Decision to make |
|---|---|---|
| Backend selection | Load balancer | Which eligible instance receives this connection or request? |
| Health checks | Load balancer or orchestrator | When should an instance stop receiving new work, and when can it return? |
| Retries | Client, proxy, or service mesh | Which failures are safe to retry, and how many attempts are allowed? |
| Circuit breaker | Client library or proxy | When should new work be limited or rejected because an upstream is overloaded? |
| API gateway policy | API gateway | Which API, route, identity, or quota applies before the request reaches a service? |
| Service-mesh policy | Mesh data plane and control plane | How should service-to-service traffic, retries, and telemetry be configured? |
Products can combine these features, but they answer different questions. A retry is another attempt, not another balancing algorithm; retrying a non-idempotent operation can repeat its effect. A circuit breaker limits calls to an unhealthy dependency. An API gateway can route by host or path and apply API policy. A service mesh may configure proxy-level routing and resilience for service-to-service calls. For the boundary between gateway routing and backend balancing, see API Gateway.
Measure before switching
Record per-backend request or connection counts, queue depth, errors, and response-time percentiles. Keep health checks, retries, and circuit-breaker limits fixed while comparing policies; otherwise a lower latency percentile may come from rejecting more requests or retrying more often.
The companion benchmark deep dive includes a runnable Python simulation with 10,000 requests, four backends, and a mixed-duration workload. It compares round robin, least connections, and power of two choices. It is a simplified simulation, not a production result: it leaves out network delay, backend failures, retries, and shared dependencies. Use it to explore assumptions, then replay representative traffic or test in staging before changing a production policy.
A short decision path
- Remove unhealthy backends from the eligible pool and confirm user-facing health separately.
- If backends and request costs are similar, start with round robin.
- If capacity differs predictably, consider measured weights. If connection or request work varies, use a policy whose metric reflects that work.
- If requests need stable key placement, evaluate consistent hashing and its hot-key behavior.
- Hold retries, circuit breakers, affinity, and health settings steady while measuring the result.
Do not choose an adaptive policy just because it sounds more responsive. It needs an accurate signal and a clear fallback for stale metrics or unhealthy hosts. A simpler policy with good health checks can be easier to operate than a more complex one whose decisions are hard to explain.
Conclusion
No algorithm balances every workload. Choose based on backend capacity, connection and request duration, queue visibility, and the proxy’s actual behavior. Measure the policy under representative conditions, keep retries and health controls explicit, and use a specialized policy only when its signal solves a real problem.
Category
Related Posts
Load Balancing Algorithms: Workloads and Benchmarks
Compare round robin, least-connections, and two-choice routing under mixed request durations with a reproducible workload and operational trade-offs.
Consistent Hashing for Load Balancing
Learn how consistent-hash rings, virtual nodes, and bounded-load policies reduce reassignment, and when sticky sessions still make sense.
Cache Stampede Prevention
Compare cache-stampede controls by the duplicate work they prevent and the failure modes they add, from local single-flight to distributed leases.