Tail latency is the latency at a high percentile of a service’s response-time distribution, such as the 99th or 99.9th, and it characterizes the slowest requests the service delivers. The -th percentile is the latency that a fraction of requests meet: .

Percentiles measure properties of the distribution that a mean cannot. Variability in service and arrival times inflates the tail well before utilization approaches 1, and fan-out across many servers makes per-server events that are rare frequent at the root. The underlying queueing model is in Queueing Theory and Latency, Throughput, and Utilization; the queueing side of fan-out and hedging is simulated in Queueing Models and Tail Latency.

Percentiles and the mean

The latency distribution of a production service is typically right-skewed and often multimodal, with separate modes for a fast path, a cache-miss path and a GC-pause path. The mean combines the modes into a value that no request experiences. Millsap (2010) defines performance by the response time of an individual task and recommends stating requirements as percentile specifications in place of averages.

In a synthetic example (lognormal with , a million samples), the mean is 1.65, the median 1.00, p95 5.19, p99 10.29 and p99.9 22.05. The mean lies at the 69th percentile ( for a lognormal), above the latency of most requests and far below that of the slowest. It describes neither the typical request (p50) nor the latency a service commits to (p99 and above). Service-level objectives are therefore stated on percentiles. A target such as “p99 < 100 ms over a 28-day window” is checkable and corresponds to a share of requests, and the tolerated 1% forms an error budget for deploys, failovers and hedging load.

Variance and utilization

The growth of response time as in Queueing Theory is the M/M/1 result. The M/G/1 queue, with Poisson arrivals and any service distribution, makes the role of variability explicit. The Pollaczek-Khinchine formula gives the mean queueing delay as

where is the squared coefficient of variation of service time. The delay is the product of the utilization pole and a variance factor . Deterministic service () halves the M/M/1 wait, and a service distribution with produces a wait 5.5 times the M/M/1 wait at the same utilization. Occasional slow requests, such as a 100 ms compaction stall among 1 ms lookups, delay every request queued behind them. Headroom in average utilization reduces only the first factor and leaves the variance factor unchanged.

Percentiles share the pole. For M/M/1 the response-time distribution is exponential, so the -th percentile is : p99 is 4.6 times the mean and p99.9 is 6.9 times. Since the mean scales as , tail percentiles grow at the same rate near saturation. Bursty arrivals increase delay in the same way. Kingman’s (1961) heavy-traffic approximation for the G/G/1 queue replaces with , where is the squared coefficient of variation of interarrival times, so arrival variability and service variability enter symmetrically. The burst example in Queueing Theory is a numerical instance.

Fan-out amplification

In the fan-out pattern analyzed by Dean and Barroso (2013), a root server sends a request to leaves and waits for all of them, so the slowest leaf determines the response time. If the leaves’ latencies are independent with distribution ,

The -th percentile of the root is the -th percentile of one leaf. For the root median is the leaf’s 99.31st percentile and the root p99 is the leaf’s 99.99th. Dean and Barroso’s example uses servers that typically respond in 10 ms but have a 99th-percentile latency of one second: with one server, one request in 100 takes a second, and with a fan-out of 100, of requests do. A single server’s p99 therefore lies near the 37th percentile of the root. In a measured Google service they report a p99 of 10 ms for a single random leaf request measured at the root, 140 ms for all leaf requests to finish, and 70 ms for 95% of them to finish, so waiting for the slowest 5% accounted for half of the root’s p99.

flowchart TD
    R[Root: fan out to k leaves, wait for all] --> L1[Leaf 1: fast]
    R --> L2[Leaf 2: fast]
    R --> LD[Leaves 3 to k-1: fast]
    R --> LS[One leaf in its slowest 1%]
    L1 --> J[Join: response ready when the last leaf answers]
    L2 --> J
    LD --> J
    LS --> J
    style R fill:#e3f2fd
    style LS fill:#f9d0d0,stroke:#c00
    style J fill:#f9d0d0,stroke:#c00

A simulation with the lognormal population above reproduces the formula (a request’s latency is the maximum of independent draws):

import numpy as np
rng = np.random.default_rng(0)
lat = rng.lognormal(0.0, 1.0, 1_000_000)      # p50=1.00, p99=10.29
 
for k in [1, 10, 100]:
    fan = lat[: len(lat) // k * k].reshape(-1, k).max(axis=1)
    print(k, np.percentile(fan, 50).round(2), np.percentile(fan, 99).round(2))

The results are p50 = 1.00 and p99 = 10.29 at fan-out 1, p50 = 4.47 at fan-out 10, and p50 = 11.69 and p99 = 41.36 at fan-out 100, against and from the formula. Independence is an assumption of the formula, and on real servers it fails in two directions, as Fan-out on a real server measures.

Dean and Barroso attribute per-server variability to contention for shared local resources (CPU, caches, memory and network bandwidth), background daemons that “can generate multi-millisecond hiccups” when scheduled, contention for global resources such as network switches and shared file systems, periodic maintenance (log compaction, garbage collection; SSD-internal garbage collection “can increase read latency by a factor of 100 with even a modest level of write activity”), multiple layers of queueing in servers and switches, CPU power and thermal throttling, and the wake-up latency of energy-saving modes. Some of these sources can be removed, but they argue that at scale not all of them can, so systems must be designed to be tail-tolerant.

Fan-out on a real server

The formula takes one leaf’s latency distribution and assumes the leaves draw from it independently. To test both inputs, I ran 64 redis-server processes on one VM and a Go client that, for each root request, sends GET to distinct servers chosen at random, waits for all replies, and records the root latency and each leaf’s latency from its own send to its reply. Each fan-out was run three times with 20,000 measured root requests, closed-loop with one root request outstanding. The figure replays the recorded histograms and computes in the page from the recorded single-leaf distribution.

20501002005001 ms2 ms5 ms10 ms10.10.0110⁻³10⁻⁴medianp99one leaf's p99latency t (log scale)fraction slower than t
Root, fan-out 16Independent (one leaf measured alone)Measured
median110 µs248 µs
p99336 µs482 µs
slower than 135 µs15%99.9%
Recorded data, replayed: 60,000 root requests per fan-out (three runs of 20,000) from a Go client to 64 redis-server processes on one 4-vCPU VM, each request a GET sent to k distinct servers at once. The independent curve is F(t)k, computed in the page from the recorded single-leaf distribution; the measured curve is the root's own recorded latency. Measured fan-outs: 1, 4, 16, 64; at other k only the prediction is drawn.

The table gives means over the three runs, in microseconds, with the standard deviation across runs where it exceeds 10% of the value. “Independent” is computed from the leaf distribution measured alone (); “loaded” computes from the leaf distribution measured within the same fan-out. The last two columns give the share of root requests slower than one leaf’s p99 measured alone (134 µs averaged over the three runs; the figure uses the pooled value, 135 µs).

Leaf p50Root p50, independentloadedmeasuredRoot p99, independentloadedmeasuredSlower than 134 µs, measured
1515151611341341471.0%1.9%
479791161101832512353.9%25%
16157108287248329 (±55)1,05548015%99.9%
644531321,0197481,054 (±788)3,691 (±1,138)1,432 (±311)47%100%

At the root exceeds the leaf by about 10 µs, the client’s time to hand the send to the leaf’s connection and to collect the reply.

The leaf distribution depends on the fan-out. A leaf’s median latency rose from 51 µs alone to 79, 157 and 453 µs at fan-outs of 4, 16 and 64. Each root request makes server processes and client goroutines runnable at once (at the client hands out all 64 sends within about 40 µs), on 4 vCPUs, so leaves queue for CPU behind each other. The single-leaf distribution therefore understates every root percentile: at the measured median was 2.3 times the independent prediction, and the share of roots slower than one leaf’s p99 was 99.9% against the formula’s 15%. The size of this effect is specific to the testbed, where the leaves share 4 vCPUs. The mechanism is not: a fan-out request loads whatever its leaves share, including the root’s CPU and network interface and the switch port toward it (the incast pattern), and the per-leaf latency that enters the formula is the latency at that load.

Correlated leaves amplify the tail less than independent ones. Using the leaf distribution measured at the same fan-out brings the predicted median within 5% of the measurement at , 16% at and 36% at , but overpredicts the tail: at the measured root p99 was 480 µs against 1,055 µs predicted from the loaded leaves, and at it was 1,432 against 3,691. Leaves in one request were slow together. The intraclass correlation of log leaf latency within a request, the share of its variance explained by which request a leaf belonged to, was 0.28 to 0.30 at and 0.23 to 0.25 at and 64 (three runs each). A positive correlation makes the maximum of draws stochastically smaller than for independent draws with the same marginals, since a stall that delays many leaves at once contributes one slow maximum where independent stalls would contribute chances at one.

The two errors have opposite signs. With the single-leaf distribution, the formula predicted a median 5.7 times too low (132 against 748 µs) and a p99 within the run-to-run spread of the measurement. The formula is exact under its assumptions, and its predictions are as accurate as the leaf distribution supplied to it and the independence of the leaves. For capacity planning, leaf latency has to be measured under the fan-out load that production generates. With taken from that loaded distribution, is an upper bound on the slow fraction when leaf latencies are positively associated, and the gap between bound and measurement grows with the correlation.

Measuring and aggregating percentiles

Percentiles do not compose arithmetically. The p99 of a union of request streams is not the mean, the maximum or any fixed function of the per-stream p99s, so averaging per-host or per-minute p99s produces a number that is not a percentile of any population of requests. Aggregation requires the distributions: full histograms, or mergeable quantile sketches. HdrHistogram records into logarithmic buckets with a configured number of significant digits. DDSketch bounds the relative error of every quantile and merges exactly. t-digest concentrates its accuracy at the extreme quantiles. The figure above stores its data the same way, as counts in log-spaced bins, each spanning a factor of .

A high percentile needs many samples. Of 20,000 requests, 20 lie above the p99.9, and the estimate depends on those 20. The root p99.9 at was 3,418 µs on average with a standard deviation of 1,074 µs across three runs of 20,000 requests, while the median varied by 6%. An objective on p99.9 therefore needs a window that holds thousands of samples above the threshold.

Load generators that issue a request only after the previous one completes undercount stalls. If the server stalls for one second, a closed-loop client records one slow request and sends no others during the stall, while users arriving at the planned rate would have queued behind it. Tene calls this coordinated omission; wrk2 corrects it by measuring each request from the time a constant-rate schedule intended to send it. The fan-out measurement above is closed-loop by design, since it measures the latency of one root request in isolation, and its percentiles exclude queueing behind other root requests.

Tail-tolerant techniques

Dean and Barroso describe the following techniques for tolerating per-server variability:

  • Hedged requests. The client sends the request to one replica and, if no reply arrives within about the 95th-percentile latency, sends a second copy to another replica and uses the first answer. The additional load is about 5% by construction, and the response time becomes the minimum over two draws in the cases where the first draw was slow. In their benchmark, reading 1,000 keys spread over 100 BigTable servers, hedging after 10 ms reduced p99.9 from 1,800 ms to 74 ms with 2% additional requests.
  • Tied requests. The request is enqueued on two servers, each told the other’s identity, and the server that starts executing it first cancels the other copy. The second copy is sent after about two network message delays, 1 ms or less. This targets queueing delay without the hedge’s wait before the second copy. In their benchmark, tied requests reduced the median by 16% and the p99.9 by nearly 40% on an idle cluster, kept latency on a cluster running a concurrent sort job close to the idle cluster’s latency without them, and added less than 1% disk utilization.
  • Micro-partitions and selective replication. Data is divided into many more partitions than machines (their example is about 20 per machine), so load can be moved in small increments and hot partitions can receive extra replicas.
  • Latency-induced probation. Requests are withheld from a replica observed to be slow, often because of an unrelated co-located job, and shadow requests continue to measure it until it recovers.
  • Good-enough responses and canaries. When result quality permits, the root returns the answers of the leaves that have replied instead of waiting for stragglers. A canary request is sent to one or two leaves before fanning out, so that a request exercising an untested code path cannot crash every leaf at once.

These techniques leave the speed of each server unchanged and act on the distribution from which the client samples: the minimum of two draws instead of one, avoidance of draws known to be slow, and tolerance for missing draws. The hedging measurement in Fan-out on a real server adds a condition to the first: the hedge delay has to be large compared with the client’s cost of arming and sending the hedge.

Sources