Square CloudSquare Cloud

p50, p95 and p99 latency: what they mean

p95 latency is the response time that 95% of requests stay under, so only 1 in 20 takes longer. p50 is the median, the typical case, and p99 shows the tail: the slowest 1% that an average hides.

Updated 8 min read

Learning objectives

After reading this article you will be able to:

  • Understand what p50, p95 and p99 say about response times
  • Calculate a percentile by hand and in code, and read a percentile chart
  • Know what to investigate when tail latency goes up
On this page

Your API averages 80 ms, yet every so often someone says the page froze. Both are true: the average describes a user who doesn't exist, and the person who complained landed in the tail of slow requests. Monitoring tools show p50, p95 and p99 instead of a single number so you can see that tail.

If you don't yet separate network time from processing time, start with what latency is.

What do p50, p95 and p99 mean?#

A percentile is a position in a sorted list. Sort every response time in a period from fastest to slowest: p95 is the value that 95% of them stay under.

Percentile How many requests took longer What it shows
p50 (median) Half The typical experience
p95 5%, 1 in 20 Where the slow tail begins
p99 1%, 1 in 100 The plausible worst case, in the words of Google's SRE book

Always read the number with its window ("p95 of 320 ms over the last 5 minutes") and with where it was measured. A p95 of 40 ms on the server and 400 ms in the browser don't contradict each other: the second includes the network, TLS and the download.

Why is the average misleading?#

Response times are not symmetric: most cluster near a low value, and a few take far longer (a query that waited on a lock, a garbage collection pause, an external call that hit its timeout). That long right tail drags the mean up.

Here are 20 response times from one route, already sorted, in milliseconds:

text
42 45 47 48 50 51 52 53 55 56 58 60 62 65 70 75 90 120 480 1900

The mean is 174 ms, and no request took anywhere near that. Eighteen of the twenty finished within 120 ms, and the other two took 480 ms or more. As Google's SRE book puts it, a simple average hides tail latencies and changes in them.

How is a percentile calculated?#

The simplest method is called nearest rank:

  1. Sort the N values from smallest to largest.
  2. Compute the rank: p/100 times N, rounded up.
  3. The percentile is the value at that rank.

With the 20 requests above:

  • p50: 0.50 x 20 = 10, the 10th value, 56 ms.
  • p95: 0.95 x 20 = 19, the 19th value, 480 ms.
  • p99: 0.99 x 20 = 19.8, rounded up to 20, the 20th value, 1,900 ms.

In code:

js
// percentile.js: run with `node percentile.js`
function percentile(values, p) {
  const sorted = [...values].sort((a, b) => a - b);
  const rank = Math.ceil((p / 100) * sorted.length); // nearest rank
  return sorted[Math.max(rank, 1) - 1];
}

const latencies = [42, 45, 47, 48, 50, 51, 52, 53, 55, 56, 58, 60, 62, 65, 70, 75, 90, 120, 480, 1900];
const mean = latencies.reduce((sum, v) => sum + v, 0) / latencies.length;

console.log(`mean: ${mean.toFixed(0)} ms`); // 174 ms
for (const p of [50, 95, 99]) {
  console.log(`p${p}: ${percentile(latencies, p)} ms`); // 56, 480 and 1900 ms
}

The NIST statistics handbook describes methods that interpolate between two neighboring values, so different tools can report slightly different numbers for the same data; with thousands of requests the gap disappears. And p99 needs volume: with 20 samples, it is simply the maximum.

In production, tools count requests into time buckets (a histogram) and estimate the percentile from those counts. So never average percentiles: the Prometheus documentation says that averaging precomputed quantiles yields statistically nonsensical values. To combine servers or periods, merge the histograms and compute the percentile again.

What is tail latency and why does it matter?#

Tail latency is the latency of the slowest requests, above p95 or p99. "Only 1%" sounds small, but it weighs more than the percentage suggests.

A page rarely makes a single request. If it fires 10 independent API calls, the chance that at least one lands in the slowest 1% is 1 minus 0.99 to the power of 10, about 9.6%. With 100 calls, as in a service that queries many servers to build one answer, it passes 63%. "The Tail at Scale", a paper by Google engineers, covers exactly this: when one request fans out to many parts, each part's tail becomes the common experience of the whole. Your heaviest users also make the most requests, so they hit the tail most often.

How do you read a percentile chart?#

The chart usually draws one line per percentile over time. Each point is the percentile of the requests in that window (one minute, five minutes, an hour). What to look at:

  • The gap between lines. p50 and p99 close together mean consistent response times. A p99 ten times the p50 is a tail worth investigating, even if p50 looks fine.
  • Which lines move. p50 and p99 rising together mean everything got slower (load, CPU, the database); only p99 rising points to a small group of requests (one route, one customer, one dependency).
  • The volume next to it. In windows with few requests, such as overnight, p99 is close to the maximum and jumps around: don't react to a spike in a window with 30 requests.
  • Errors alongside. A 500 that fails in 5 ms can even lower latency, while a timeout shows up in the tail. Read latency and error rate side by side.

Edge or origin latency?#

When traffic goes through a CDN or a reverse proxy, there are two places to measure. Edge latency is measured at the point of presence serving the visitor and, when the response is not cached, includes the trip to your server. Origin latency is the time your server took to answer.

Comparing them splits the problem:

Edge Origin Where the time goes
High High The application, the database or a dependency
High Low Between the edge and the server (distance, new connections) or the size of the response
Low High Most responses come from cache, and only the ones that reach your server are slow

In the third case, the right Cache-Control takes even more load off the origin.

Each tool defines both measurements its own way, so read its documentation before comparing numbers.

What is a reasonable target?#

There is no p95 that is good for every case: a route that reads one record by ID and one that builds a report need different targets. A practical approach:

  1. Measure each route for a few days, peak hours included.
  2. Write a target for each type of route (simple read, write, search, report) as a service level objective (SLO), in the format of Google's SRE book: "99% of requests complete in under X ms". The book also shows layered targets, such as 90% under 1 ms, 99% under 10 ms and 99.9% under 100 ms for a read operation.
  3. Keep p99 well below your timeouts. If a proxy cuts at 30 s and your p99 is already at 20 s, a traffic bump turns into 504 errors, as load balancer timeouts shows.

For pages, web.dev considers a TTFB of 0.8 s or less good, as a rough guide, and assesses Core Web Vitals at the 75th percentile of page loads. Even Google's target is a percentile, not an average.

What should you check when p99 goes up?#

First, check whether p50 rose too. If it did, the whole system got slower, and why your app is slow walks through CPU, memory and disk. If only the tail rose, the suspects are different:

  1. One specific route. Sort routes by p99. It is often a query without an index that only hurts customers with lots of data.
  2. Queueing. Near capacity, requests wait for each other, and p99 rises before p50. Compare with request volume at the same time.
  3. An exhausted connection pool. The request waits for an available database connection: the time shows up in the application, not in the queries.
  4. Dependencies and retries. A slow external API with a 5 s timeout and one retry produces a 5 to 10 s tail.
  5. Runtime pauses. Garbage collection and a blocked event loop in Node.js delay every request in flight.
  6. Cold caches. Right after a deploy or restart, the first requests hit empty caches.

Log the duration and the route on every line, and finding slow requests becomes a search, as how to read your app logs explains.

How to do this on Square Cloud#

On the Pro and Enterprise plans, Square Cloud analytics shows, for applications published as a site, p50, p95 and p99 latency at the edge and at the origin, along with HTTP request logs. That lets you compare edge and origin and match the spikes against the logs.

On every plan, cookieless web analytics shows those applications' routes and status codes over ranges of up to 7 days, and 4xx/5xx error monitoring shows when responses start failing. CPU, RAM and network metrics are kept for 24 hours on every application, and for 7 days (hourly average and peak) on Pro and Enterprise for applications from 512 MB, which helps you see whether a p99 spike matched CPU or memory at the limit.

Two facts take suspects off the list. Containers are always on, with no cold starts, so the tail doesn't come from an application waking up. And database hosting, from the Standard plan, runs in the same datacenter as your applications, with about 1 ms average latency. See what each plan includes on the Analytics page.

API hosting

APIs in always-on containers, with no cold starts

Cookieless analytics

FAQs

What is p95 latency?

It is the value that 95% of the response times measured in a window stay under. If p95 is 300 ms, 1 in 20 requests took longer than that.

What is the difference between p95 and p99?

p95 leaves out the slowest 5% of requests, and p99 leaves out only the slowest 1%. p99 shows more of the tail, but it needs more requests in the window to be stable.

Why not use average latency?

A few very slow requests pull the average up, and it may not match any real request. Percentiles show the typical case and the plausible worst case separately.

Can I average the p95 of several servers?

No. The average of percentiles is not the percentile of the whole set. To combine servers or time windows, merge the histograms or raw measurements and compute the percentile again.

What is a good p95 for an API?

There is no universal number: it depends on what the route does and who is waiting for it. Measure where you are, set a target per type of route and keep p99 well below client and proxy timeouts.

Next articleWhat is OpenAPI (Swagger) and how to document your APIOpenAPI is an open standard for describing an HTTP API in a YAML or JSON file. See how it relates to Swagger, a minimal example and how to generate docs and clients.