Hedged Request
A hedged request sends a duplicate of a request to a second server when the first has not answered after a short delay, then uses whichever response arrives first. It reduces tail latency, the slowness of the slowest few percent of requests, at the price of some extra load. Dean and Barroso describe the technique in “The Tail at Scale” as one way to keep a service responsive when individual components occasionally stall.
Why tail latency needs its own remedy
Occasional slowness has independent causes: a busy replica, a garbage-collection pause, a queue, a network hiccup. A request that fans out to many components is slow if any one of them is. A rare slow event per component therefore becomes a frequent slow event per request. Retrying after a timeout does not help much, since the timeout must be long to avoid false alarms, and by then the user has already waited.
Mechanism
- Send the request to one replica.
- If no response arrives within the hedge delay \(H\), send the same request to a different replica.
- Return the first response; cancel the other if possible.
A common choice for \(H\) is a high percentile of the observed latency, such as the 95th. Then only about 5 percent of requests trigger a hedge, so extra load is about 5 percent, while a request stuck on a slow server gets a second chance after a delay that is short compared with the stall.
A simulation
A simulation of 200,000 requests (hypothetical latency model, in milliseconds) uses a body of log-normal latencies with a median near 100, plus a 2 percent chance of an additional 400 to 1,000 ms stall. The second copy’s latency is drawn independently. Baseline: p50 101, p99 810, p99.9 1,075.
| hedge delay | extra requests | p99 | p99.9 |
|---|---|---|---|
| none | 0 | 810 | 1,075 |
| p90 (142) | 10.0% | 244 | 303 |
| p95 (159) | 5.0% | 259 | 317 |
| p99 (810) | 1.0% | 810 | 940 |
Hedging at the 95th percentile cuts p99 from 810 to 259 for 5 percent more requests. Hedging at the 99th percentile does almost nothing for p99, because the delay is already as long as the stall. The benefit depends on the tail shape: it works when slowness is a rare property of one replica and typical latency is short compared with the delay. If most of the delay is the work itself and both calls share it, as with a long text generation whose duration is set by the length of the output, the second call does not finish earlier and the hedge gains little for its cost; only an independent queue or replica stall is left to avoid, and that is a small part of the total.
Conditions for using it
- Idempotency. Two copies of the request may both run to completion. Reads and operations that can be repeated safely qualify. Operations with side effects, such as charging a card or sending a message, need an idempotency key so the second copy is recognized, or must not be hedged.
- Capacity headroom. Extra load rises with lower percentiles. During overload, hedging adds work to a system already slow and can worsen the problem; hedge budgets that cap the share of hedged requests prevent this.
- Independent failure. The second request has to go to a different replica or path. If the slowness comes from shared state, both copies are slow together.
- Billing. For paid model APIs both copies can be billed. The 5 percent extra load is also roughly a 5 percent extra bill.
Neighbors
A retry waits for a failure or timeout and then repeats. A hedge repeats while the first attempt is still in flight. A timeout with fallback bounds the worst case at the timeout plus the fallback’s time but gives a different, often lower-quality answer. Tied requests, also in the Tail at Scale paper, send both copies at once and cancel the loser as soon as one starts executing, trading more load for a shorter wait.
References
Discover more from Insightful Data Lab
Subscribe to get the latest posts sent to your email.
