A request fans out to many backends and waits for all of them. The service is slow even though each backend looks healthy on average. How do you diagnose and fix it?
Sketch your own answer first, then compare it with the one below.
A strong answer
The effect is that the response time of the whole request is the maximum over the fan-out. The more backends involved, the more likely at least one is in its slow tail on any given request. So the tail of each backend, not its average, sets the user's experience.
Diagnose by looking at per-backend percentiles and at which backend was slowest for each slow request. Look for common causes: queueing behind long requests, background maintenance, garbage collection, shared-resource contention, and uneven load.
Fixes in roughly increasing complexity:
- Reduce variance at the source: smaller units of work, priority for short requests, throttling background jobs.
- Better load balancing so no backend runs a longer queue than its peers.
- Hedged requests: send a duplicate to a second replica after waiting a short time, and take the first answer. Costs a small amount of extra load for a large cut in the tail.
- Tied requests, where duplicates cancel each other once one starts.
- Reduce the fan-out width, or accept partial results with a deadline.
Every fix has a price. Hedging adds load and only suits idempotent requests, so it is a poor first move.
Sources
- Jeffrey Dean, Luiz André Barroso (2013). The Tail at Scale.