Try
↑ ↓ move↵ openesc close

Interview prep / Retries and circuit breakers

Senior · Retries and circuit breakers · System design interview question

A search request fans out to 50 index shards and the 99th percentile latency is dominated by one slow shard. Someone proposes hedged requests. What do you check before agreeing?

Sketch your own answer first, then compare it with the one below.

A strong answer

First, why the tail is slow. Hedging helps when slowness is local and temporary: a garbage collection pause, a compaction, a busy neighbour. A second replica is probably fine at that moment. It does not help if the slowness comes from the request itself, such as a query that is heavy everywhere, because the copy is slow too and the load doubles for nothing.

Second, the arithmetic of the cost. If the hedge fires at the 95th percentile of shard latency, about 5 percent of shard calls send a second copy, so about 5 percent more load. Across 50 shards, a page is likely to hedge at least one shard, since the chance that none of 50 passes the 95th percentile is 0.95 to the 50th, about 8 percent. That is fine, as each hedge is cheap, but check the capacity has room for it.

Third, safety. The call must be idempotent, which a search is. Cancel the loser so the work stops. Send the copy to a different replica. And suppress hedges when the system is already loaded, because under overload every request passes the delay and hedging turns into a load multiplier. Put hedges under a budget.

Measure before and after on the real tail, and keep a switch to turn it off.

Sources

Learn it by running it

The retries, timeouts and circuit breakers lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms