Lab · Traffic

Load balancer

A load balancer sits in front of several identical servers and decides which one handles each request. Watch how the algorithm, a slow server and a crash change where requests go — and who gets errors.

Try it

Lab time 3.0 s
Clients, 6 IP addressesClients6 IP addresses6 req/sLoad balancer, Round robinLoad balancerRound robinchecks every 2 sServer A, in poolServer Ain pool2 busy · 8 sentServer B, in poolServer Bin pool2 busy · 8 sentServer C, in poolServer Cin pool3 busy · 8 sent
About each part:
  • Clients — 6 IP addresses — healthy — 6 req/s
  • Load balancer — Round robin — healthy — checks every 2 s
  • Server A — in pool — healthy — 2 busy · 8 sent
  • Server B — in pool — healthy — 2 busy · 8 sent
  • Server C — in pool — healthy — 3 busy · 8 sent
  • Request
  • Response
  • Error / rejected
  • Health check
Requests
25
Succeeded
17
Failed
0
In flight
8
latency
1.3 s
latency
1.4 s

Numbers add up:25 requests = 17 succeeded + 0 failed + 8 in flightThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

Algorithm

Next server in order, one at a time.

Traffic
6 req/s
Failures
Server A
Server B
Server C

Tip: you can also click a server in the diagram to crash or recover it.

Release v2

Now: every server runs v1. v2 requests so far: 0, failed: 0, rollbacks: 0.

v2 has a bug: it fails about 1 request in 5.

Where requests went

  • Server A33%
  • Server B33%
  • Server C33%

The tick mark shows an equal 33% share.

What just happened

  1. 0.0sInfo: Load balancer started with 3 servers using Round robin.

Compare two algorithms on the same requests

Both sides get the same requests at the same moments, from the same clients. Only the algorithm differs, so any gap in the numbers comes from the algorithm. Both sides start with 20 seconds already run.

Side 1 algorithm

Next server in order, one at a time.

Side 2 algorithm

Send to the server with the fewest requests in progress.

8 req/s
Lab time 20.0 s
Side 1 Round robin
Clients, 8 req/sClients8 req/sLoad balancer, Round robinLoad balancerRound robinServer A, normalServer Anormal2 busy · 34%Server B, 4× slower, SLOWServer B4× slower9 busy · 33%SLOWServer C, normalServer Cnormal2 busy · 33%
  • Clients — 8 req/s — healthy
  • Load balancer — Round robin — healthy
  • Server A — normal — healthy — 2 busy · 34%
  • Server B — 4× slower — SLOW — 9 busy · 33%
  • Server C — normal — healthy — 2 busy · 33%
Side 2 Least connections
Clients, 8 req/sClients8 req/sLoad balancer, Least connectionsLoad balancerLeast connectionsServer A, normalServer Anormal3 busy · 46%Server B, 4× slower, SLOWServer B4× slower3 busy · 16%SLOWServer C, normalServer Cnormal2 busy · 38%
  • Clients — 8 req/s — healthy
  • Load balancer — Least connections — healthy
  • Server A — normal — healthy — 3 busy · 46%
  • Server B — 4× slower — SLOW — 3 busy · 16%
  • Server C — normal — healthy — 2 busy · 38%
  • A request on its way
  • Its reply, moving back up
  • Refused: the server was full

Each box is one request, named after its client: 0.13 is the client at 10.0.0.13. Each side draws only a few at a time, so the boxes stay easy to follow. The table counts every request.

Compare two algorithms on the same requests: the numbers for each side and the gap between them
MeasureSide 1 · Round robinSide 2 · Least connectionsGap
Requests sent164164Same requests
Succeeded147155Least connections higher by 8
Failed30Least connections lower by 3
p50 latency (median)1.3 s1.3 sSame
p95 latency (slowest 5%)4.5 s3.0 sLeast connections lower by 1.5 s
Share sent to server B33%16%Least connections lower by 17 points

Changing a setting starts both sides again, so the numbers always describe one setup from its start. A server rejects a request when it already has 10 in progress.

What this model simplifies
  • Time is slowed down so you can follow each request: a network hop takes ~0.2 s here instead of well under a millisecond.
  • Servers get slower as they get busier (+12% per concurrent request) and reject work beyond 10 concurrent requests. Real servers degrade in less tidy ways.
  • The load balancer itself never fails. In production you run at least two, behind DNS or a floating IP.
  • Health checks are simple "are you alive?" probes. Real checks often hit an endpoint that also verifies dependencies.