TAIL LATENCY

Your p99 is someone's every request

L214 MINSYSTEMS & LOW-LEVEL
PREDICT

Each backend is slow on 1% of calls. A request fans out to 20 backends and waits for all of them. Roughly what fraction of requests is slow?

A backend that is slow 1% of the time looks healthy on its own. Its p99 sits right at the edge of the slow path. Now put it behind a fan-out. The parent sends one request to N backends and waits for all of them, so the parent is slow if any one call is slow. That happens with probability 1 - 0.99N: 18% at N = 20, 63% at N = 100.

You cannot make every backend perfect. You can stop waiting for the slow one. A hedged request sends a backup to another replica once the first call is late and takes whichever reply arrives first.

▶ SIMULATION
PARENT (waits for all 20)
requests done 0 / 1000
p50 — · p99 —
—
P(PARENT HITS A SLOW BACKEND)
measured: —
1 − 0.9920 = 18.2%
BACKENDS (each)
calls 0
p95 —
slow calls (150–250 ms): 0 of 0 (0%)
SLOparent p99 ≤ 50 ms
parents over 50 ms0 of 0
✓ parent p99 ≤ 50 ms
SCHEDULE
01[CLIENT]fan out to FANOUT backends, wait for every reply
02[CLIENT]parent requests 1–200
03[CLIENT]parent requests 201–400
04[CLIENT]parent requests 401–600
05[CLIENT]parent requests 601–800
06[CLIENT]parent requests 801–1000
07[CLIENT]report percentiles
Start of wait for all scenario. 7 steps.
// wait for every shard
const parts = await Promise.all(shards.map((s) => s.query(q)));
// latency = the slowest of N calls

Watch the parent’s p99 and the probability box. WAIT FOR ALL measures 18% slow parents against a formula of 18.2%, and the p99 lands in the slow path. HEDGED REQUESTS runs the same backends, with the same 1% slow calls, and holds p99 at 30 ms for about 1% extra load. The load is that low because fast calls here never pass 15 ms, so the hedge fires only for the slow 1%. With real latencies, where fast and slow overlap, a hedge at the p95 costs about 5%.

TUNE IT NOT YET

Every backend meets a 50 ms p99 on its own: only 1% of its calls are slow. Start at FANOUT 1 and raise it. Find the smallest fan-out at which the parent's p99 breaks the 50 ms SLO.

GOAL: p99 > 50 ms at this fan-out, ≤ 50 ms at every smaller one

FIX IT NOT YET

Write hedge(request, backends, delay). backends[i].call(request) sends the request to replica i and returns how many ms its reply takes. Return the ms at which the caller has its first reply. Send to backends[0]; only if that reply takes longer than delay, send one backup to backends[1] at time delay. Backups are extra load: do not send one when the primary answers in time.

Mental model:

when a request waits for all of N things, it inherits the worst of them. A rare slow path becomes the common case as fan-out grows. Measure and set SLOs on percentiles, not means, and attack the tail directly: hedge after the p95, so a request is slow only when two independent calls are both slow.

IN PRODUCTION

Search and feed services that scatter to shards, microservice pages that call a dozen services, distributed databases reading from replicas. Bigtable, Cassandra speculative retry, and gRPC hedging policies all send backup requests. The usual culprits behind the slow 1% are GC pauses, compaction, a noisy neighbour, or a cold cache.

IN INTERVIEWS

“Every service meets its p99, but the page is slow. Why?” Compute 1 - 0.99^N for the fan-out, explain why the parent sees the tail, and propose hedged or tied requests after the p95. Mention the cost (a few percent extra load) and that backups must go to a different replica and be safe to repeat.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.

USED IN

Chapters that build on this lesson.

NEXT: CAPSTONE: THE LATENCY CLIFF →