Load Balancer

A load balancer spreads incoming requests across several servers, so no single server is overwhelmed and a failed server can be routed around.

Round robin

Load balancer · Round robint = 0

A

0 ticks of work queued · 0 handled

B

0 ticks of work queued · 0 handled

C

0 ticks of work queued · 0 handled

Round robin sends requests to A, B, C, A, B, C… in turn, whatever they are doing.

Step 1 / 14
Most work queued on one server
0
Failed requests
0

Step by step

The example above, written out — the same steps the animation plays.

  1. 1Round robin. Round robin sends requests to A, B, C, A, B, C… in turn, whatever they are doing.
  2. 2#1 (slow) → A. A: next in turn. Every slow request lands on A, because they arrive every third tick — exactly in step with round robin.
  3. 3#2 (slow) → B. B: next in turn.
  4. 4#3 (slow) → C. C: next in turn.
  5. 5#4 (slow) → A. A: next in turn. Every slow request lands on A, because they arrive every third tick — exactly in step with round robin.
  6. 6#5 (slow) → B. B: next in turn.
  7. 7#6 (slow) → C. C: next in turn.
  8. 8#7 (slow) → A. A: next in turn. Every slow request lands on A, because they arrive every third tick — exactly in step with round robin.
  9. 9#8 (slow) → B. B: next in turn.
  10. 10#9 (slow) → C. C: next in turn.
  11. 11#10 (slow) → A. A: next in turn. Every slow request lands on A, because they arrive every third tick — exactly in step with round robin.
  12. 12#11 (slow) → B. B: next in turn.
  13. 13#12 (slow) → C. C: next in turn.
  14. 14Done. Most work queued on one server: 9 ticks. Round robin balances the number of requests, not the work.

What's happening?

  1. Round robin hands requests to each server in turn — fair in count, blind to how heavy each request is.
  2. Least connections sends each request to the server with the fewest requests in progress, so slow work spreads out.
  3. When a server stops answering, health checks mark it unhealthy and traffic goes to the others.

Where you'll meet it

Every site with more than one server: AWS ALB, NGINX, HAProxy, Kubernetes Services. It is also what makes rolling deploys possible without downtime.

Common mistake

Keeping user state (sessions, uploads) in one server's memory: the next request may land elsewhere. Keep state in a shared store, or use sticky sessions knowingly.

FAQ

Why did round robin put every slow request on server A?

Slow requests arrived every third tick — in step with the three-server rotation. Real traffic has patterns like this more often than you'd think.

Layer 4 vs layer 7?

Layer 4 balances TCP connections without reading them; layer 7 reads HTTP and can route by path, header or cookie.

What does a health check do?

It regularly asks each server "are you OK?" (or watches for failures) and stops sending traffic to servers that fail.