23/39
Part 4 of 6 · Latency and the tailLearn and do

Fan-out makes the slow case the common case

Many serving systems split a request across many machines, the leaves. The request is only as fast as its slowest leaf.

LeafThis time
leaf 110 ms
leaf 210 ms
leaf 31,000 ms: slow this time
leaves 4 to 10010 ms

The root waits for the last leaf, so this request takes 1 s.

Dean and Barroso's paper The Tail at Scale sets it up with a server that usually answers in 10 ms, but has a p99 of one second. One such server makes 1 request in 100 slow. A request that must collect answers from 100 such servers in parallel is slow 63% of the time.

Check that number. Each leaf is fast with probability 0.99, independently, and the request is fast only if all 100 are:

Chance
one leaf is fast0.99
all 100 are fast0.99^100 = 0.366
at least one is slow1 - 0.366 = 0.634, about 63%

The paper's second case has each server slow on only 1 request in 10,000, but 2,000 servers per request. Then 1 - 0.9999^2000 = 0.181, which the paper calls almost one in five.

Google's SRE book makes the same point from the other side. When users depend on several backends to build their page, one backend's p99 can easily become the page's median.

Each leaf needs a far stricter target than the request

Share of requests slow, when each leaf is slow 1% of the time
1 leaf
1%
10 leaves
9.6%
50 leaves
39.5%
100 leaves
63.4%
1,000 leaves
about 100%

Turn the math around to get the requirement. To keep a 100-way fan-out fast 99% of the time, each leaf must be fast with probability 0.99^(1/100) = 0.9999. Your p99 target for the request is a p99.99 target for every leaf.

The paper's measurements from a real Google service agree. Measured at the root, the p99 for one random leaf request to finish was 10 ms. Waiting for every leaf took 140 ms at p99. Waiting for 95% of them took 70 ms.

In the editor, write slow_share(p_slow, leaves): the share of requests that are slow when each one waits for every leaf. Then turn it around with leaf_target(request_fast, leaves): how often each leaf must be fast for the whole request to be fast that often.