Your backends are not identical. Some machines are faster than others. How do you balance load across them?
Sketch your own answer first, then compare it with the one below.
A strong answer
Start by naming the problem with even splitting. Round robin and random give each server the same share, so a slower server receives more than it can finish and its queue grows.
Options:
- Weighted round robin or weighted random. Give each server a share proportional to its capacity. This is simple and works when capacity is known and stable.
- Queue-aware strategies such as least connections or power of two choices. A slow server's queue is longer, so it loses comparisons and gets fewer requests without anyone configuring a weight.
- Latency-aware routing, where the balancer prefers backends that have been answering quickly.
Static weights go stale when machines are shared or throttled. Adaptive schemes handle change but need a trustworthy signal. Heterogeneity is also one source of the tail latency variation that large services have to design around.
Sources
- Jeffrey Dean, Luiz André Barroso (2013). The Tail at Scale.
- Michael Mitzenmacher (2001). The Power of Two Choices in Randomized Load Balancing.