Video in progress

How do round robin and least connections differ?

Round robin hands requests to servers in turn: 1, 2, 3, 1, 2, 3. Least connections picks the server with the fewest open connections right now — which is fairer when requests differ in weight.

📖 Answer

Round robin is the simplest and is enough in most cases. The problem shows up when requests are not uniform: say one server gets 3 heavy report requests in a row and is busy for 10 seconds, but round robin keeps giving it new requests.

Least connections takes this into account: a busy server gets fewer new requests.

There are other options too:

  • weighted round robin — a bigger share for a stronger server (for example, 2:1);
  • IP hash — the same IP always goes to the same server;
  • random — random choice, which gives results close to round robin at large numbers.

In practice Nginx defaults to round robin, and if services are stateless and requests are short, you don't need to change it. For long-lived connections like WebSocket, least connections works better.