Understanding Load Balancing Algorithms: Round Robin, Weighted, Random, and Least Connections
This article explains four core load‑balancing algorithms—Round Robin, Weighted Round Robin, Random, and Least Connections—detailing their principles, advantages, drawbacks, and typical scenarios where each method best fits modern backend systems.
Round Robin
Round Robin distributes each incoming request to the next server in a static list, looping back to the first server after the last one.
Advantages : Simple to implement; only a server list and a current index are required; provides even distribution when all servers have similar capacity.
Stateless : No need to track load or request history.
Disadvantages : Ignores differences in CPU, memory, or network bandwidth; a weaker server can become a bottleneck.
Typical use cases : Homogeneous clusters such as static web farms, CDN edge nodes, small internal APIs.
Weighted Round Robin
Weighted Round Robin extends the basic algorithm by assigning a numeric weight to each server. The scheduler cycles through the list, emitting a server proportionally to its weight.
Weight configuration : Higher‑weight servers receive more requests. Weights can be static (e.g., based on CPU cores) or updated dynamically by monitoring tools.
Algorithm sketch :
maxWeight = max(weights)
gcd = GCD(weights)
currentWeight = 0
while true:
for i in range(len(servers)):
if currentWeight == 0:
currentWeight = maxWeight
if weights[i] >= currentWeight:
select server i
currentWeight -= gcd
breakAdvantages : Reflects heterogeneous capacity; predictable distribution when weights are correct.
Disadvantages : Requires correct weight assignment; weight changes add computational overhead (GCD calculation) and need a monitoring pipeline.
Typical use cases : Cloud environments mixing high‑spec and low‑spec instances, micro‑service deployments where proportional traffic is required.
Random
The Random algorithm selects a server using a pseudo‑random number generator for each request.
Advantages : Minimal state, negligible CPU cost, easy to implement.
Statistical property : Over a large number of requests the distribution converges to uniform (law of large numbers).
Disadvantages : Short‑term spikes are possible; a server may receive a burst of traffic while others stay idle.
Typical use cases : Homogeneous, stateless pools such as cache clusters or high‑throughput back‑ends where occasional imbalance is acceptable.
Least Connections
Least Connections assigns a request to the server that currently holds the fewest active connections, providing a dynamic view of load.
Advantages : Adapts to varying request durations; ideal for long‑lived connections (WebSocket, database pools, game servers).
Operational cost : Requires continuous tracking of connection counts, adding monitoring overhead.
Limitations : For uniformly short requests the metric may not correlate with CPU or I/O load, reducing effectiveness.
Typical use cases : Services with persistent connections, APIs with variable processing times, L7 load balancers (e.g., Nginx upstream module) combined with health checks in cloud‑native deployments.
Choosing an algorithm
Select the method that matches server heterogeneity, request characteristics, and operational constraints:
Use Round Robin for simple, homogeneous clusters where no per‑request monitoring is needed.
Use Weighted Round Robin when server capacities differ and you can maintain accurate weight values.
Use Random for high‑throughput, stateless workloads where occasional imbalance is tolerable.
Use Least Connections for services with long‑lived or highly variable request processing times.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
