Skip to content

Percentiles and tail latency

A service answers 1,000 requests. 980 of them take 50 ms. The other 20 take 5 seconds, because they hit a lock, a cold cache or a slow disk. The mean is (980 × 50 + 20 × 5,000) ÷ 1,000 = 149 ms.

No request took 149 ms. 98% of users waited a third of that, and 2% waited thirty-three times as long. A dashboard that shows only “average latency: 149 ms” hides both groups. If the slow requests become more frequent, the mean moves a little. If they become slower, the mean moves a little. The people who suffer are in the part of the data the mean flattens.

The SRE book makes the same point with a service at 1,000 requests per second: an average of 100 ms can sit alongside 1% of requests taking five seconds, and the mean cannot tell you.

Mental model. A latency measurement is a distribution, not a number. A single figure summarises one place on it. Choose the place that matches the question: what do most users get, and what do the unluckiest get?

A percentile is a value that a given share of the requests are at or below. Sort every request by its latency, from fastest to slowest, and read the value at a position.

  • p50, the median: half of the requests are faster. It is what a typical request gets.
  • p95: 95% are at or below it, and 1 request in 20 is slower.
  • p99: 99% are at or below it, and 1 in 100 is slower.
  • p99.9: 1 in 1,000 is slower.

For the 1,000 requests above, with the rule that the p-th percentile is the value at rank p% of the sorted list:

Measure Value
Mean 149 ms
p50 50 ms
p95 50 ms
p99 5,000 ms

The mean falls between the two groups, while p50 and p95 say that the usual request is fast, and p99 says that something is wrong for the unlucky ones. Together they describe the system. The high percentiles are the tail, and a system whose tail is long is said to have high tail latency.

It is tempting to say that the slowest 1% matters little. Two things make it matter more than that.

A page makes many calls. Suppose each call to a backend is slow 1% of the time, and a page makes 100 of them in parallel and waits for all. The page is fast only if every call is fast, which happens with probability 0.99 to the power of 100, about 36.6%. So 63.4% of pages meet at least one slow call. The Tail at Scale, a paper from Google, makes this point about fan-out: the more servers a request touches, the more the tail of each one becomes the typical experience of the user. With a rarer problem, at 0.1%, the share falls to 9.5%, which is why teams that fan out widely watch p99.9 and not only p99.

The slow requests are not always random. A request that has more to read takes longer, so the users with the most data, the longest history or the most items in a cart can be the ones in the tail. A tail of slow requests can be a tail of your most active customers.

Try it: the mean and the p99 on the same curve

Section titled “Try it: the mean and the p99 on the same curve”

The lab below shows how long a request spends in a service with four servers that share one queue, each taking 20 ms on average. The chart draws the mean, the 95th percentile and the 99th percentile as the service gets busier. Utilisation is how busy the servers are, as a share of what they could do. The table under the chart gives the figures at the levels worth knowing.

Requests arrive at a service with a few servers that share one queue. Raise the arrival rate toward what the servers can serve and watch the time a request spends in the system: it rises slowly at first and then sharply. Change the number of servers, the service time, and how much it varies.

100 req/s
Servers sharing the queue
4
20 ms
1
ClientsHealthy<1%ServiceBusy50%
ClientsHealthy<1%ServiceBusy50%

Each dot stands for many requests. The numbers show the real rate.

No bottleneck: every component has headroom.

Response time at this load

Utilisation
50%Busy
Mean time in the system
21.7 ms1.1× the service time
99th percentile
95.3 ms95th percentile: 63 ms
Requests in the system
2.20.2 of them waiting

Little's Law: 100 requests per second × 21.7 ms = 2.2 requests in the system on average.

Time in the system as utilisation rises

  • Mean
  • 95th percentile
  • 99th percentile

A line that leaves the top of the chart keeps going up: the time grows without limit as utilisation approaches 100%.

Use the left and right arrow keys to move along the curve, and shift with an arrow to move ten points. The reading is announced.

What each level of utilisation costs, with your other settings
UtilisationMeanTimes the service time95th percentile99th percentile
50% · your load21.7 ms1.1× the service time63 ms95.3 ms
70%27.1 ms1.4× the service time75 ms109.9 ms
80%34.9 ms1.7× the service time94.8 ms137.9 ms
90%59.4 ms3× the service time163.3 ms243.9 ms
95%109.1 ms5.5× the service time310.4 ms471.3 ms
99%509 ms25× the service time1.51 s2.31 s
0 ms
Metrics
ComponentStateUtilisationOffered (req/s)Served (req/s)Rejected (req/s)p50p95p99
ClientsHealthy<1%10010000 ms0 ms0 ms
ServiceBusy50%100100016 ms63 ms95 ms
Traffic
100 req/s
Successful
100 req/s
Error rate
0%
Mean latency
22 ms

Illustrative values, not benchmarks of any real product.

Model notes

Assumptions

  • Requests arrive at random, as a Poisson process, at a constant average rate.
  • Each node is one queue, served first-come first-served by several identical slots (instances × concurrency).
  • Service times are random with the stated mean; by default they are exponentially distributed.
  • Each node is analysed separately, with the traffic it receives treated as Poisson.
  • Requests arrive independently at random, at a steady average rate, and are served in the order they arrive from one shared queue.

Simplifications

  • Above capacity there is no steady state. The model switches to a fluid approximation: the node serves at capacity, its queue grows until it reaches its limit, and further requests are rejected.
  • Percentiles assume an exponential tail. A service-time variability other than exponential changes the mean wait but not the shape of the tail.
  • A node frees its slot as soon as it has done its own work, before waiting on the services it calls. Real thread-per-request servers hold the slot, so a slow dependency exhausts them faster than this model shows.
  • A request calls its dependencies one after another. Parallel fan-out is not modelled.
  • When a caller times out and gives up, the callee still finishes the work, so abandoned requests keep consuming capacity.
  • Retries add load. Their backoff and jitter decide when that load arrives, which only the per-request simulation shows.
  • Retry feedback is solved from the healthy starting point, so it finds one stable outcome. Systems that stay stuck in overload after the cause is gone are not shown.
  • A throughput limit (for example maximum writes per second) is modelled as slower service, not as a separate rate limiter.
  • A caller’s timeout counts the mean time its dependencies take, not their full distribution.
  • The curve is the steady state: it assumes the arrival rate has stayed the same for long enough to settle. A real system takes time to build a queue, and a short burst can fill one even below capacity.
  • Service times are exponential in shape. The variability control changes the mean wait, by a factor of (1 + variability) ÷ 2, and not the shape of the tail.

Parameter values are illustrative. They are not benchmarks of any real product.

Read the table with the defaults. At 50% utilisation the mean is 21.7 ms and the 99th percentile is 95.3 ms, 4.4 times the mean. At 90% the mean is 59.4 ms and the 99th percentile is 243.9 ms. At 95% the mean is 109.1 ms and the 99th percentile is 471.3 ms. The percentiles rise along with the mean, and they stay well above it.

Now set Servers sharing the queue to 1 and Service time to 10 ms. At 90% utilisation the mean is 100 ms and the 99th percentile is 460.5 ms. That is 4.6 times the mean, and it is not a coincidence of these settings: for one server with exponentially distributed service times, as the lab assumes by default, the time in the system is itself exponential, and its 99th percentile is the natural logarithm of 100, about 4.6, times its mean, however busy the server is. With four servers the ratio is not constant, but it stays between 3.9 and 4.5 across the table.

What happens if you set a goal on the average?

Section titled “What happens if you set a goal on the average?”

A team sets a goal: “mean latency under 100 ms”. The service has four servers of 20 ms each, as in the lab. It meets the goal through every level in the table up to 90%, where the mean is 59.4 ms. At 90% 1 request in 100 takes longer than 243.9 ms, and nobody is alerted. At 95% the mean is 109.1 ms, the goal is finally broken, and by then 1 request in 100 is taking more than 471.3 ms. By the time the average is bad, the tail has been bad for a while.

A goal on a percentile, “p99 under 250 ms”, is broken just above 90%: at 91% the 99th percentile is 268.8 ms, while the mean is 64.9 ms and looks fine. That is the usual argument for service level objectives written on percentiles: they trip earlier, and they describe the users who are suffering.

One more trap is in how percentiles are collected. Take the 1,000 requests from the start and imagine that two servers handled them. Server A served the 980 that took 50 ms, so its p99 is 50 ms. Server B served the 20 that took 5,000 ms, so its p99 is 5,000 ms. The average of the two p99 figures is 2,525 ms. The p99 of all 1,000 requests together is 5,000 ms. The average of the percentiles says 2.5 seconds, and the truth is twice that.

The fix is to keep the distribution, usually as a histogram, which counts how many requests fell in each latency range, and to merge histograms, not percentiles. A percentile is read from the merged histogram at the end. A monitoring system that stores only a pre-computed p99 per server cannot give a correct p99 for the fleet.

Percentiles: check your understanding

This quiz needs JavaScript to check your answers.

Question 1 of 3

Out of 1,000 requests, 970 took 40 ms and 30 took 2,000 ms.

What is the mean latency?

Enter a number and choose its unit.

milliseconds
Question 2 of 3

The same 1,000 requests: 970 took 40 ms and 30 took 2,000 ms.

What are the median (p50) and the 99th percentile (p99)?

Choose one answer.

Question 3 of 3

A page makes 50 calls in parallel and waits for all of them. Each call is slow 1% of the time, independently of the others.

What share of pages meet at least one slow call?

Enter a number and choose its unit.

%
  • A mean can describe nobody: 980 requests at 50 ms and 20 at 5,000 ms give a mean of 149 ms, and no request took 149 ms.
  • A percentile is the value that a given share of requests are at or below. p50 is the typical request, p99 is the one-in-a-hundred slowest.
  • The tail matters because pages make many calls. With 100 parallel calls that are each slow 1% of the time, 63.4% of pages meet a slow call.
  • In the lab, the 99th percentile stays between 3.9 and 4.5 times the mean as utilisation rises. A goal on the mean is broken after the tail has already been bad for a while.
  • Percentiles cannot be averaged. Keep histograms and merge them.

Next: Little’s Law, which links the number of requests in a system to the time each one spends there.

Your progress

Built by GhaziAlibi.

© ShardCraft. All rights reserved.