Skip to content
WebsiteHosting.com

concept Delivery & performance

Adaptive load balancing with EWMA latency

A latency estimate can guide the next request, but sending the request can change the next estimate. Follow two backends round by round to see how EWMA weighting affects that feedback.

Latest recorded source check · P0164

What it means

A load balancer can use an exponentially weighted moving average (EWMA) to estimate each backend’s response time and send the next request to the backend with the lower estimate. Giving the newest latency sample more weight makes the estimate respond faster. But the routing decision can itself change the next sample: a backend that looked fast before it received the work may look slow afterward.

Try it

Simulation. Follow backend A through the first round below. Then change only EWMA weight for new sample from 100% to 50%, keeping all four rounds. Compare A’s estimate after round 1, not just the name of the next backend. Try 0% to see whether a slow sample can still change the route. Reset restores the original example.

Adaptive load balancing with EWMA latency

Show why measured latency can help or destabilize adaptive routing

Simulation
Modeled outcome: Trace

The next decision follows the updated latency estimates, which depend on prior routing in this toy feedback loop.

Adaptive load balancing with EWMA latency: synthetic scenario inputs
Replaces all inputs with the documented starting example and the indicated change. Reset restores the starting example.
EWMA feedback across successive decisions

Selected upstream

  1. Round 1A (A < B; A wins ties)
  2. Round 2B (A > B; A wins ties)
  3. Round 3A (A < B; A wins ties)
  4. Round 4B (A > B; A wins ties)

Next decision

  1. Switches3
  2. Next upstreamA
  3. Exact orderingA < B
RoundA beforemsB beforemsSample AmsSample BmsA aftermsB afterms
1203060306030
2603020702070
3207060306030
4603020702070

Scores use the modeled samples and alpha. Decimal values below are rounded to three decimal places for display; these are not measured upstream response times.

Evaluated inputs

Required scenario evidence
provided
Sample availability
both
A base latency
20 ms
B base latency
30 ms
EWMA weight for new sample
100 %
Decision rounds
4 count
Added latency for selected backend
40 ms
Alternating observation perturbation
0 ms

Both observations supplied each round (e.g. hypothetical probes), deterministic added latency on selected backend and alternating perturbation, choose smaller estimate, A at equality. Real EWMA policy may account for elapsed time, missing data, exploration, outstanding work and multiple clients. This is not Envoy least-request or Peak EWMA implementation; alpha0 freezes estimate by design.

About this model

The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.

Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.

The starting estimates are the base latencies: 20 milliseconds (ms) for A and 30 ms for B. In each round, the selected backend gets 40 ms added to its sample for that round only. Both samples are available, and there is no added noise. At 100% weight, each new sample replaces the corresponding estimate.

RoundEstimates before (A/B, ms)ChoiceSamples (A/B, ms)Estimates after (A/B, ms)
120 / 30A60 / 3060 / 30
260 / 30B20 / 7020 / 70
320 / 70A60 / 3060 / 30
460 / 30B20 / 7020 / 70

The four choices contain three switches. A would be next because its final estimate is 20 ms against B’s 70 ms. That next choice is a prediction from the last row, not a fifth completed round.

Which measurement decides the route?

Read each row from left to right. The model chooses using the estimates it has before the round’s samples arrive; if the estimates are equal, it chooses A. It then receives one observation for each backend, as if both had been probed. A’s 60 ms sample in round 1 therefore cannot explain why A was chosen in round 1. It explains why the choice moves to B in round 2.

For each backend, the update is new estimate = (1 − alpha) × old estimate + alpha × new sample, where 50% means an alpha of 0.5. At 50%, A’s first estimate moves halfway from 20 to 60 ms, landing at 40 ms. B stays at 30 ms, so B is still chosen in round 2. That round’s samples of 20 and 70 ms bring the estimates to 30 and 50 ms. Smoothing changed the estimates without changing either of the first two choices.

At 0%, A still produces a 60 ms sample whenever selected, but its estimate stays at 20 ms. B’s estimate stays at 30 ms, so A keeps receiving the work. Zero switches here means the estimate ignored the observations, not that A consistently responded faster.

Noise is separate from the cost of being selected. Starting from the defaults, set the alternating perturbation to 5 ms. It adds 5 ms to B on odd rounds and to A on even rounds. The first samples become 60 and 35 ms: A’s increase comes from being selected, while B’s comes from the perturbation. At 100% weight, both changes pass straight into the estimates.

Set alpha to zero while keeping the default base estimates and penalty. Samples still reflect which upstream was selected, but the after-sample scores remain 20 and 30 ms, so all rounds choose A. A stable decision can therefore result from ignoring feedback rather than from stable observed latency. The scene exposes before, sample and after values for each round so those explanations remain distinguishable.

The model compares the unrounded EWMA estimates exactly. If rounded scores look equal, read the exact ordering beside the chosen backend; A wins only a true tie. This is a rule of the fixture, not a claim about a particular load balancer.

In practice

To understand a switch, line up three observations: the estimates available at the decision, the backend selected, and the samples that arrived afterward. Check whether a sample exists before interpreting its value. With Sample availability set to B-missing, the simulation stops without choosing a route. A measured high latency gives you a value to compare; an absent measurement gives you no such value.

Also check what the routing policy compares. The documented Envoy least-request policy uses active-request counts; in its unequal-weight variant, those counts can reduce a backend’s effective weight. Counting work in progress is not the same as smoothing elapsed response times. This simulation implements neither Envoy least-request nor Peak EWMA.

In the four-round example, neither base latency changed. The choices alternated because sending work changed what was observed, and those observations informed the next choice. Before calling one backend the best destination, ask when its latency was measured and under what load. An EWMA summarizes the samples that went into it; it does not establish how fast the next request will be.

Frequently asked questions

Editorial questions based on the listed sources and explicitly labeled local examples.

What does a large alpha change?

It weights recent samples more strongly. That can respond quickly to change but can also follow noisy measurements. Alpha zero freezes the estimate in this model.

Why can routing oscillate?

Routing changes load, and that changes the next observations. Our deterministic penalty illustrates the feedback; it does not prove a specific production policy is unstable.

Should a missing measurement be treated as zero?

No. A missing score is not a zero-latency sample. This fixture returns unknown when B evidence is missing; alpha zero is different because the supplied scores are retained deliberately.

Is EWMA a latency percentile?

No. It is a weighted estimate of observations over time. A percentile describes a distribution and needs its own estimation method.

Sources & model boundaries

Primary references used for this explanation. The interactive example is an educational model, not a live check.

  1. Envoy load balancers

    adaptive load balancing. Equal-weight and unequal-weight least-request policies differ; active request count can reduce effective weight. This does not establish an EWMA selection formula.

    Checked .

  2. NIST EWMA control chart

    exponentially weighted moving average. EWMA reduces the weight of older data over time; routing policy is a separate application.

    Checked .

Report an issue. Include the article URL and ID, not passwords or access keys.