Percentiles and Tail Latency (p50, p95, p99)
Overview
An average latency hides how real users feel. Percentiles describe the whole spread of response times, and the slowest few percent, called the tail, are what users actually complain about. This lesson shows how to read percentiles and why the tail matters more as systems grow.
Detailed Notes
What is a percentile
The Nth percentile is the value that N% of requests are faster than.
- p50 (the median): half of requests are faster. The typical experience.
- p95: 95% are faster, so 1 in 20 is slower.
- p99: 99% are faster, so 1 in 100 is slower.
- p99.9: 1 in 1,000 is slower.
Example: p50 = 90 ms, p95 = 250 ms, p99 = 1,200 ms. Half of requests finish in 90 ms, but 1 in 100 takes longer than 1.2 s. The slow end of the distribution is called the tail, and tail latency is the delay those unlucky requests suffer.
The problem it solves
The average (mean) adds up all times and divides by the count. Latency is usually skewed: many fast requests and a few very slow ones. The average describes no real request.
Example: 99 requests take 100 ms and 1 takes 5,000 ms. The average is (99 x 100 + 5,000) / 100 = 149 ms, which looks fine. But one request in a hundred waits five seconds. A team can see "80 ms average" on its dashboard while users complain that the app freezes. A typical user makes dozens of requests per session, so most users hit at least one slow one. The p99 would have shown it at once.
How it works
Measuring. Record every request's latency (or use histograms: counts of requests per time bucket) and compute percentiles. Never average percentiles across servers. The average of two p99 values is not the p99 of the whole; merge the underlying histograms instead.
Targets. A latency target (an SLO, a service level objective) usually reads: "99% of requests complete within 300 ms over 30 days." Targets at p95 or p99 keep the tail honest.
Fan-out amplifies the tail. Fan-out means one request triggers calls to many other services and waits for all of them. If each service is slow 1% of the time and a request calls 100 of them, the chance at least one is slow is:
1 - 0.99^100 = about 63%
A rare 1% slowdown in each part becomes a common slowdown for the user. This is why large systems obsess about p99 of each component.
Causes of a slow tail:
- Queueing behind a slow or busy request.
- Pauses while a program cleans up its memory (garbage collection).
- A noisy neighbour: another workload on the same machine steals resources.
- Retries and timeouts: a failed attempt adds a full timeout delay.
- Background jobs (backups, clean-up) competing for resources.
Reducing the tail:
- Timeouts and deadlines: never wait forever; pass the remaining time budget to downstream calls.
- Hedged requests: if an answer is slow, send a duplicate request to another copy of the service after a short delay and use whichever answers first. Only safe for idempotent operations, ones that give the same result when repeated, like reads.
- Load shedding: reject extra requests early to protect the rest.
- Isolation: keep heavy or slow work away from latency-critical paths.
- Smaller fan-out: fewer dependencies means fewer chances for a slow one.
A simple example
Think of a school bus that must collect 100 children from 100 houses before leaving. If each child is late one day in a hundred, the bus is late about two days out of three, because any one slow child delays everyone. That is fan-out.
System design example
A shopping homepage assembles content from 30 services in parallel. Each has an excellent p99 of 100 ms, yet the page often takes over a second, because the slowest of 30 calls decides the result. The team adds a deadline per call with graceful fallbacks (skip the recommendation box if it is late), hedges a few idempotent reads and reduces the number of calls. The page's p99 drops sharply while the average barely moves.
Summary
- The average hides slow requests; use percentiles.
- p50 is typical; p95 and p99 show the tail.
- Fan-out turns rare slowness into common slowness: 1 - 0.99^N.
- Never average percentiles; merge histograms.
- Reduce the tail with timeouts, hedging, load shedding and isolation.
Architecture Diagram
The page waits for the slowest backend.
- 1The aggregator calls several backends in parallel.
- 2Most answer quickly; one hits its slow tail.
- 3The response waits for the slowest unless a deadline cuts it off.
Common Interview Questions
Finished this lesson?
0 of 91 lessons done · 0% of the course

