Why you need it
Everyone who clicks has to wait for the answer, and people leave when the wait is long. The easy number to watch is the average wait, but the average hides the people who waited far too long. You need a number that shows them.
Think of it like this
A bus that is "on time on average". Most days it comes at 8:00, but once a week it comes at 8:40. The average says 8:06, which sounds fine, yet once a week you are late for work. What you care about is the bad day.
Where you’ll find it
- Amazon: Built its Dynamo database to promise a fast answer for 99.9 out of 100 requests, not on average.
- Google: Wrote The Tail at Scale on keeping the slowest 1% fast when one search touches thousands of machines.
- Most monitoring tools: Show p50, p95 and p99 out of the box: Prometheus, Datadog and AWS CloudWatch.
What to know first
Latency. The time between asking and getting the answer, usually counted in milliseconds (ms). 1,000 ms is one second.
Percentile. Line up every wait from fastest to slowest. The 99th percentile (p99) is the wait at position 99 out of 100: only 1 in 100 waited longer.
p50. The middle of the line, also called the median. Half waited less, half waited more. It is what a normal visit feels like.
How it works
- Measure every request, not a sample of averages. Each answer records how long it took. Tools keep these as a histogram: counts of how many took 0 to 10 ms, 10 to 20 ms, and so on, so percentiles can be read off later.
- Read three numbers. p50: the normal visit.p99: the slow visits, 1 in 100.p99.9: the very slow ones, 1 in 1,000. Busy sites watch this one, because 1 in 1,000 is still thousands of people a day.
- Never trust the average. A few very slow requests barely move the average, and many fast ones can hide them. Two systems with the same average can feel completely different. This is the point of the animation.
- Slow tails add up. A page that asks 100 servers for parts of the answer must wait for the slowest one. If each server is slow 1 time in 100, about 63 of every 100 pages are slow. So the tail of each part becomes the normal case for the whole page.
- Set the goal as a percentile. A good goal says "99% of requests answer within 300 ms", not "the average is 100 ms". See SLOs and error budgets for how teams write and track these goals.
An example
100 visitors load a page. 97 wait 0.1 seconds, 1 waits half a second, and 2 wait 8 seconds.
The average is about 0.26 seconds. That looks healthy.
Line them up: the p50 is 0.1 seconds, but the p99 is 8 seconds. Two people out of every hundred sat watching a blank screen.
Only the percentile shows the problem. That is why teams put p99 on the dashboard, next to the average or instead of it.
Further reading
- The Tail at Scale, Jeff Dean and Luiz Barroso, Google. The classic short paper on why the slowest 1% matters and how Google fights it. Start with this one.
- How NOT to Measure Latency, Gil Tene (talk). A famous talk on the common mistakes, like averaging percentiles. Watch the first 20 minutes.
- Monitoring Distributed Systems, Google SRE book. Latency is the first of Google's four golden signals. Free to read.
- Latency numbers every programmer should know, Colin Scott. An interactive chart of how long memory, disk and network really take.