Four load balancers, one stream of traffic.
The same requests hit round robin, random, least connections and two random choices at once. Change the traffic, kill a server, switch health checks off, and see which algorithm copes.
Round robin
Takes turns. Ignores how busy each server is.
- p95
- 0.0s
- median
- 0.0s
- errors
- 0.0/s
Random
Picks any server. Simple, but luck decides.
- p95
- 0.0s
- median
- 0.0s
- errors
- 0.0/s
Least connections
Sends to the server with the fewest requests in flight.
- p95
- 0.0s
- median
- 0.0s
- errors
- 0.0/s
Two random choices
Picks two at random and uses the less busy one.
- p95
- 0.0s
- median
- 0.0s
- errors
- 0.0/s
All four balancers receive exactly the same requests. Each column is a server: the outlined block is being served, the blocks above it are waiting, and amber blocks are the slow requests. A latency is how long a request took from arrival to completion.
Share of the cluster's capacity that traffic uses.
Most requests are quick but a few are slow. Round robin and random deal slow requests out blindly, so they stack up behind each other on unlucky servers. Compare the p95 of each balancer.
Simulated time: 0 s · 0 requests per balancer
What you are looking at in the load balancing lab
A load balancer decides which server handles each request. The four balancers here use different rules, but they receive exactly the same requests at exactly the same moments, so any difference you see comes from the algorithm and not from luck.
Each server handles one request at a time and keeps a queue. In uniform traffic every request costs the same. In mixed traffic most requests are quick and a few are slow, with the same average load. The metric to watch is p95 latency: how long the slowest 5% of requests take. Averages hide the pain that real users feel.
When you kill a server, the balancer does not know instantly. It learns at the next health check. Until then it keeps sending the dead server its share of traffic, and those requests fail. Turn health checks off and the failures never stop.
Things to try in the load balancing lab
- Leave traffic on Mixed at 85% load and let it run. Compare p95 across the four panels. Round robin and random usually pile slow requests onto unlucky servers.
- Switch to Uniform. Round robin is suddenly excellent: taking turns is fair when every request costs the same.
- Drag the load to 100% or above. Every balancer's queues grow without limit. A balancer cannot create capacity.
- Kill server S2 with health checks set to 8 s. Watch the error rate until the check removes it, then restart it and see it rejoin.
- Set health checks to Off and kill a server. Errors never stop, because the balancer never finds out.
Why load balancing matters in a system design interview
Interviewers want to hear that you choose an algorithm for a reason: round robin when requests are uniform, least connections when request cost varies widely, and two random choices as a cheap way to get most of the benefit without a global view of every server's load.
They also listen for failure handling: health checks, how long detection takes, connection draining, and the fact that the balancer itself needs to be redundant. The load balancing lesson covers layer 4 versus layer 7, sticky sessions and global balancing, and ties into consistent hashing for cache-friendly routing.