How does a least-connections load balancer decide, and what does it need to know?
Sketch your own answer first, then compare it with the one below.
A strong answer
For each new request it picks the server with the fewest requests in flight. It is a rough proxy for the shortest queue, so it adapts when some servers are slower or some requests are expensive.
It needs a current count per server. A single balancer can keep that count itself by incrementing when it forwards and decrementing when the response returns. With several balancers, each only sees its own traffic unless counts are shared, so each has an incomplete picture.
It treats every connection as equal weight, which is wrong when some connections are idle keep-alives and others are heavy. A newly added server with zero connections can be flooded until its queue catches up, so many implementations add a slow-start period.
Power of two choices asks only two servers and gets much of the same benefit, which is the usual follow-up question.
Sources
- Michael Mitzenmacher (2001). The Power of Two Choices in Randomized Load Balancing.