Course map
Stage 1: Foundations
Stage 2: Data Integration
Stage 3: Building & Shipping
Stage 4: Customer Engagement
Stage 5: Specialization

Part 11 / Topic 2 of 7

Latency percentiles

The mean is the one number guaranteed to describe no actual request. Latency distributions have long right tails, and the tail is where users suffer:

# examples/01_measure_latency_with_percentiles_not_averages.py
import random, statistics

random.seed(7)
latencies_ms = [random.gauss(120, 20) for _ in range(980)] + [random.uniform(1500, 3000) for _ in range(20)]
q = statistics.quantiles(latencies_ms, n=100)
print(f"mean {statistics.mean(latencies_ms):.0f} ms")
print(f"p50  {q[49]:.0f} ms")
print(f"p95  {q[94]:.0f} ms")
print(f"p99  {q[98]:.0f} ms   <- 1 in 100 requests takes at least this long")
# mean 160 ms
# p50 122 ms
# p95 157 ms
# p99 2187 ms <- 1 in 100 requests takes at least this long

Read it carefully: 98% of requests cluster near 120 ms, the mean says "160 ms, fine", and p99 says one request in a hundred takes over two seconds. Those 2% are Ravi's dispatchers hitting refresh — the exact people whose adoption is your success criterion. Report p50/p95/p99; use the mean for capacity maths, never for experience.

🧪 Quick quiz — answer from memory, then check.

  1. Mean latency was 160 ms but p99 was about 2,187 ms. What does that tell you?
Show the answer

A small share of requests are very slow; the mean hides them. 2% of slow requests pushed p99 above 2 seconds while p50 stayed at 122 ms. (verified against the example output above)

Done here? The practice set for Part 11 — 4 exercises with solutions — is on the part page.

Search the guide