One slow export jams a server
A team dashboard: 7,000 req/s on 4 app servers, which adds up to more than enough. But 1 request in 10 is a CSV export that takes 10 times as long, and the servers keep overloading.
Play this levelFree with an account. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
A load balancer picks a server for each request. Round robin, the usual default, just takes turns: server 1, 2, 3, 4, then 1 again. It doesn't look at how busy anyone is.
That's fine when every request takes the same time. Here a server that picks up a few exports in a row is stuck on them, and round robin keeps handing it new requests anyway. Those pile up and wait, while another server sits idle.
Least connections sends each request to the server working on the fewest right now. A server stuck on exports has many open, so new requests go elsewhere until it catches up.
On average the servers have room. It's the busiest one that overloads, and round robin is what makes one server the busiest.
What you have to achieve
7,000 requests a second at the busiest hour, 10% of them writes.
- No broken or illegal connections
- No component is overloaded
- Fewer than 0.1% of requests fail
- p99 response time under 300 ms
- Machines cost at most $1,120 / month
What you learn
Same four servers, and none overloads. When requests take different times, how a load balancer picks matters as much as how many servers sit behind it.
Check yourself
4 servers can take 8,000 req/s and 7,000 arrive. Why does one overload with round robin?
- The load balancer is too small
- Round robin keeps sending to a server stuck on slow exports, so that one gets far more work
- The database is slow
Show the answer
Round robin keeps sending to a server stuck on slow exports, so that one gets far more work. Round robin splits requests evenly, not work. A server with a few exports has much more work, and still gets its turn of new requests.
When is round robin perfectly fine?
- When every request takes about the same time
- Never
- Only with 2 servers
Show the answer
When every request takes about the same time. With even requests, taking turns spreads the work evenly too, and it costs nothing to track.