Single logo
  • Courses
  • Blog
  • About
Join for freeJoin free
Learning pathServe a Model in Production: Docker, Latency and Scaling
  1. 1
    Online, Batch or Streaming? Picking the Serving Pattern for an ML Model
  2. 2
    A Production FastAPI for an ML Model: Input Limits, /health, /ready and a Model Version
  3. 3
    Batch Scoring a Million Rows: Chunks, a Run ID and a Safe Rerun
  4. 4
    Docker Essentials for ML: Images, Containers and Volumes with a Model API
  5. 5
    Containerising a Model API: A Dockerfile for FastAPI and scikit-learn, Line by Line
  6. 6
    Latency Math: p50, p95, p99 and Why the Tail Reaches Your Users
  7. 7
    Measuring Latency of an ML API: Timing Inside with OpenTelemetry, Outside with a Load Test and Locust
  8. 8
    Making ML Inference Fast: ONNX, Micro-Batching and Quantisation, Measured
  9. 9
    Sizing and Autoscaling an Inference Service: From One Replica to a Replica Count
  1. Blog
  2. /
  3. Machine Learning
  4. /
  5. MLOps and Production ML

Learning path: Serve a Model in Production: Docker, Latency and Scaling · Step 6 of 9

Latency Math: p50, p95, p99 and Why the Tail Reaches Your Users

What p50, p95 and p99 really mean, why an average of 109 ms can describe nobody, why a p95 needs its load beside it, and why a page that makes ten calls hits a slow one about 40% of the time.

Chaand Sheikh

·27 November 2026Serving Models

What you will learn

  • Read p50, p95 and p99 as positions in a sorted list of request times
  • Explain why an average latency can describe no real request
  • Always report a percentile together with the load it was measured at
  • Work out tail amplification with 1 - 0.95^n

Before you start

  • A Production FastAPI for an ML Model
  • Basic NumPy

Our rain API is up and it answers correctly. Now we want to say how fast it is. That sounds easy, until you try to put it in one number.

Same requests, two answers

Here's one load test on the rain API, with one caller sending 640 requests, every one of them successful. Ask for a typical request and it's about 17.6 ms. That's p50. Ask for a slow one and it's about 28.1 ms. That's p95. And 32 of these requests took even longer than that.

So which number is the speed of our API? Both are true. They answer different questions.

A hundred people at a bakery

Think of a bakery on a busy morning, with a hundred customers. Each waits a different time. Line them all up, shortest wait at the front, longest at the back.

  • Walk to customer 50 and ask how long they waited. That's p50. Half waited less, half waited more.
  • Customer 95 is p95. Only five people had it worse.
  • Customer 99 is p99. Just one person had it worse.

A percentile is only a position in a sorted line, nothing more.

A percentile is a position in a sorted line p50 p95 p99 shortest wait longest wait 100 customers, sorted by how long they waited
Sort first. p50 is halfway; p95 leaves only five behind it.

The average describes nobody

Why not just take the average? Here's a small example, with numbers for illustration only. Ten requests: nine take 10 ms, and one gets stuck and takes 1,000 ms.

The average is (9 × 10 + 1,000) / 10 = 109 ms. Now look at the list. Not one request took 109 ms. The nine quick ones were far quicker, and the slow one far slower. Sorted, p50 is 10 ms, and the slow one sits at the end where you can see it.

That's why we quote percentiles. Our load test doesn't even report an average.

Percentiles in two lines

In loadtest.py, every request's time goes into one array, ms: 640 values at one caller. Then:

"p50": float(np.percentile(ms, 50)),
"p95": float(np.percentile(ms, 95)),

np.percentile works on the sorted values. With 50 it walks to the halfway point: 17.6. With 95 it walks 95% of the way: 28.1. (The full load test, with its workers, is in Measuring Latency with OpenTelemetry and Locust.)

This script stops at p95. Change the 95 to 99 and you'd get p99, but 1% of 640 is about six requests, so that number would rest on just six values. The further out you go, the more requests you need before you can trust the number.

A percentile needs its load

The row the load test returns keeps the concurrency, how many callers were sending at once, right beside p50 and p95. Here's the same API on the same machine (local CPU, one uvicorn worker, load test on the same machine):

Callers at oncep50 (ms)p95 (ms)Errors
117.628.10
232.249.30
460.286.10
8123.7171.60
16270.8356.20
32526.7717.20
641,017.31,243.60

So "p95 is 28 ms" is only half a sentence. p95 at how many callers? Always say the load along with the number. (What this table means for how many copies of the API you need is the subject of Sizing and Autoscaling an Inference Service.)

One page, ten calls

Now the part that surprises people. Say one page on a weather site shows ten towns, and it calls our API ten times at once (an illustration). Nine answers come back quickly. The tenth is one of the slow ones, and the page is still waiting on it. The page is as slow as its slowest call.

That's the tail, and that's what reaches the user. Five percent sounds rare for one call, but a user isn't making just one call.

Tail amplification

A call is slow 5% of the time, so it's fast 95% of the time. For two calls to both be fast, that's 0.95 × 0.95. So the chance that a page with n calls hits at least one slow call is:

1 - 0.95^n
Calls per pageSlow beyond p95Slow beyond p99 (1 - 0.99^n)
2about 10%
5about 23%
10about 40%about 10%
20about 64%
100about 63%
Chance of at least one slow call, 1 - 0.95^n 2 calls 5 calls 10 calls 20 calls about 10% about 23% about 40% about 64% Calculated, not measured. Assumes each call is slow on its own.
The more calls behind one page, the more often the tail is what people see.

This is arithmetic, not a measurement. It assumes each call is slow independently, and in real systems slow moments often come together. Treat it as a way of thinking. The idea holds: the more calls behind one page, the more the tail becomes what people see.

Common mistakes

  • Quoting an average. One stuck request drags it to a value no request actually had.
  • Quoting a percentile with no load. The same API went from 28.1 ms to 1,243.6 ms at p95 as callers grew from 1 to 64.
  • Trusting p99 from a few hundred requests. At 640 requests it rests on about six values.
  • Judging a page by one call's p95. A page with many calls feels the tail much more often.

Quick recap

IdeaReal number
A percentile is a position in a sorted listone caller: p50 17.6 ms, p95 28.1 ms
Averages misleadnine at 10 ms and one at 1,000 ms average 109 ms (illustration)
Say the load64 callers: p95 1,243.6 ms, same API
The tail adds up10 calls per page: about 40% hit a slow one (calculated)

Try it yourself

Add a p99 line to loadtest.py next to the p95 line, and see how far it sits from p95. Then run more requests and see whether it settles.

Built this? Share your solution in the StudyEasy AI Community.

Join free on Skool →
← Previous
Containerising a Model API: A Dockerfile for FastAPI and scikit-learn, Line by Line
Next →
Measuring Latency of an ML API: Timing Inside with OpenTelemetry, Outside with a Load Test and Locust
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool
Go deeper with a course

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)

Related articles
Python Virtual Environments: One Project, One Toolbox

Why every Python project gets its own virtual environment: two projects that need different versions of requests, python -m venv .venv, activation, pip install and the PyCharm setting that activates it for you.

Git and GitHub Fundamentals: Commits, Branches, Push and Pull

The Git you use every day, on a tiny hello-ml project: commits as save points, the staging area, a branch merged with a fast-forward, then push, clone, pull and pull requests with a teammate.

Testing a FastAPI App with pytest: Three Small Tests

A tiny FastAPI app with a Hello World route and a name route that refuses numbers, three pytest tests that check it, and what happens when the validation is deleted by mistake.

Config and Logging Instead of Hard-Coded Values in ML Training

Take the hard-coded values out of a car price training script: one config.toml read with tomllib, logging with levels and a run id on every line, and secrets read from the environment. Same RMSE, 2195, before and after.

On this page
  • Same requests, two answers
  • A hundred people at a bakery
  • The average describes nobody
  • Percentiles in two lines
  • A percentile needs its load
  • One page, ten calls
  • Tail amplification
  • Common mistakes
  • Quick recap
  • Try it yourself
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool
Go deeper with a course

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.