Load balancing: select using a signal with a known scope
Compare round robin, least request, latency-aware selection, and consistent hashing while distinguishing requests, connections, and observed load.
On this page
The question for today
What you’ll understand
- Explain the load signal used by a specified selection algorithm.
- Distinguish per-request balancing from choosing one endpoint for a long connection.
- Analyze a hypothetical two-choice selection without presenting it as every implementation's sampling rule.
A balancer cannot distribute work according to a quantity it never observes. Request counts, active streams, response latency, endpoint weights, and CPU reports are different signals with different delays. Choose the unit being assigned and the scope of each measurement before deciding whether round robin, least request, latency feedback, or key affinity fits the service.
The assignment unit changes the problem
A TCP-level balancer often selects an endpoint when a connection is created. If that connection then carries many HTTP/2 or gRPC streams, its traffic can remain concentrated on one backend. An HTTP-aware proxy can select an upstream for individual requests or streams, subject to its routing and pooling behavior. A long-lived streaming request still occupies its chosen endpoint rather than being transparently redistributed every time load changes. Count new connections, active streams, and requests separately when diagnosing an apparently uneven service.
Round robin rotates choices among available endpoints, potentially with weights, but equal assignment counts do not imply equal execution cost. One endpoint may receive expensive requests or have less CPU capacity. Least-request policies use active work counts as a signal; Envoy v1.40.0 documents different selection behavior for equal versus unequal endpoint weights. Latency-aware methods such as Linkerd 2.18's documented EWMA approach use another observation boundary. Neither an active count nor a recent response time is a complete instantaneous measurement of backend resource saturation.
Feedback improves decisions without becoming omniscient
A power-of-two-choices design samples a small candidate set and chooses the less loaded candidate according to its signal. This can avoid the coordination and herding of every caller choosing a globally minimum reported endpoint. However, each proxy generally sees only its own active requests unless an explicit reporting mechanism supplies broader information. Signals can be delayed or biased by successful completions. State the sampling and tie rules before deriving probabilities; two independent samples with replacement are not equivalent to selecting two distinct hosts.
Consistent hashing tries to keep a routing key associated with a relatively stable endpoint set. That can help cache affinity or stateful placement, but a popular key can overload its assigned endpoint. Hash balance across key space does not imply balance across request popularity or execution cost. Adding or removing endpoints changes some assignments, and locality or health policy can modify the effective set. Choose affinity because the application needs it, then measure skew and failure behavior rather than calling it a universal load-equalization mechanism.
Evaluate assignment and completed work together
Measure per-endpoint request starts, active work, completions, error rates, and resource use under comparable request mixes. A server receiving fewer requests can still consume more CPU if its requests are larger. A recovering endpoint may need a gradual ramp rather than its full nominal weight immediately. Test a slow endpoint, heterogeneous capacity, long streams, a hot affinity key, and a rolling membership change. Verify which policy layer selects locality, priority, subset, and final endpoint so that changing one weight is not mistaken for controlling the entire path.
The probability lab represents the explicitly hypothetical independent candidate draw. Reset, set p=0.20 and n=2, predict the bar for two high-load candidates has probability 0.04, then Play or Step. Separately Reset, set p=0.50 and n=2, predict that bar is 0.25, then Play or Step. The bars are exact binomial probabilities and do not implement a balancer or simulate response times. Explain why the candidate probability alone cannot establish that a selected server has spare CPU or that a latency percentile improves.
Work it through
Separate weighted counts from execution cost
A synthetic request stream has rate 900 requests/s and two eligible endpoints with weights 2 and 1. Separately, 20% of a hypothetical candidate population is high-load and two candidates are sampled independently with replacement.
The ideal weighted assignment targets are 900×2/3=600 requests/s and 900×1/3=300 requests/s. They describe counts under a fixed-set model.
If the first endpoint's average request cost is 2 ms of CPU and the second's is 1 ms, their CPU demands are 1.2 and 0.3 CPU seconds per second. A 2:1 count split is not a 2:1 CPU split.
For the separate independent candidate model, both candidates are high-load with probability 0.2²=0.04. This does not alter the weighted-rate calculation or specify an actual implementation's selection algorithm.
Weighted counts, resource demand, and sampled-candidate quality are distinct quantities. A useful load signal must match the bottleneck being controlled.
The living notebook
Explore the model
Interactive lab · probability
The assumptions behind two candidate choices
Reset, set p=0.20 and n=2, predict probability 0.04 for outcome two, then Play or Step. Separately Reset, set p=0.50 and n=2, predict 0.25, then Play or Step. This exact binomial model assumes independent replacement draws; it is not an Envoy or Linkerd load-balancer implementation.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA selection theorem needs the candidate sampling assumptions and does not by itself predict service latency.
Pause & reason
Check your understanding
Your turn
Try it yourself
Three endpoints have weights 1,2,3 under an ideal fixed-set weighted assignment of 1,200 requests/s. Find each target rate, then state why a hot consistent-hash key can violate an equal-work expectation.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Normalize weights by their total, and distinguish key-space share from request popularity.
Compare with the solution
The targets are 200,400,600 requests/s because the weight total is six. A consistent-hash policy maps key ranges, but one frequently requested key can send a disproportionate amount of work to its selected endpoint. Key-space balance alone does not make request frequency or CPU demand uniform.
Keep the idea
Take it with you
- Balance the correct unit: connection, request, stream, or measured resource demand.
- Feedback signals have scope, delay, and implementation-specific selection rules.
- Affinity and equalized load are different objectives that require separate evidence.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.