← blog · November 22, 2026

Measuring Latency Properly: Where the Average Misleads, Percentiles, Histogram Buckets and the Fraction Under a Threshold

The average hides slow requests in the tail, and percentiles cannot be averaged. Histograms versus summaries, choosing bucket boundaries, the correct order of a histogram_quantile query, and alerting on the fraction under a threshold instead of a percentile.

Describing a service's speed with one number is tempting: "average response time is 80 milliseconds." That number sits calmly on the dashboard while some of your users wait several seconds every day, and the average never shows it. Latency distributions are almost always right-skewed: most requests are fast, a small fraction are very slow, and the mean swallows that tail. This post covers how to measure latency properly: why you need percentiles, why the difference between histograms and summaries matters, and the mistakes people most often make when writing the query.

Why the average lies

If 990 out of 1,000 requests return in 50 milliseconds and 10 take 3 seconds, the mean is about 80 milliseconds. On paper everything looks fine. The 99th percentile, however, is 3 seconds. When a single page load fans out into twenty or thirty backend requests, the chance that a user hits at least one slow request is far higher than one percent. Tail latency is the latency your users actually experience.

So track at least two numbers: the median (p50) for the typical experience and p95 or p99 for the bad one. p99.9 only makes sense at high volume; on an endpoint serving a few hundred requests a minute, p99.9 is computed from one or two samples per window and is pure noise.

You cannot average percentiles

This is where the most common mistake starts. Each server computes its own p99 and the dashboard averages them. The result is not the p99 of anything. A server with very little traffic and terrible latency pulls the average more than it deserves; a slow server carrying most of the traffic can disappear in it. Percentiles are not aggregatable: neither their mean, nor their maximum, nor their average over time gives the right answer.

The correct approach is to aggregate the raw distribution. If you collect "how many requests fell below this bound" from every server and add them up, you can compute the percentile of the combined distribution. That is exactly what a histogram gives you.

Histogram or summary

Prometheus client libraries offer two types for latency.

A summary computes quantiles on the client side, inside your application, and exports the finished numbers. It is precise for a single process but carries the problem above: summaries from different instances cannot be combined. The set of quantiles is also fixed in code; you cannot decide later that you want p90 too.

A histogram counts observations into predefined buckets. Each bucket is the cumulative answer to "how many observations were less than or equal to this value" and is distinguished by the le label. The quantile is computed at query time on the server. Because counts add up, you can combine as many instances, regions or endpoints as you like.

My position is clear: use histograms in every new service. A summary only makes sense when you need a very precise quantile from a single process that will never be aggregated with others, which is rare in practice.

Writing the query correctly

A classic Prometheus histogram produces three series: _bucket, _sum and _count. The p99 across all instances is:

histogram_quantile(
  0.99,
  sum by (le) (rate(http_request_duration_seconds_bucket[5m]))
)

The order matters. First rate, then sum: counters reset when a process restarts, and rate only handles that reset correctly on an individual series. Summing first and taking the rate afterwards misreads resets as drops. If you drop the le label in sum by (le), the buckets collapse into each other and the function returns nonsense. To split by endpoint, add the label: sum by (le, route).

The mean still has a use, computed from the right source: rate(..._sum[5m]) / rate(..._count[5m]). It is handy for capacity and cost math, not for user experience.

Bucket boundaries are everything

histogram_quantile does not know how values are distributed inside a bucket; it assumes they are spread evenly and interpolates linearly. The accuracy of the result therefore depends entirely on your bucket boundaries. The default buckets shipped with client libraries are generic and may not fit your service at all.

Example: if your buckets are at 0.25 and 0.5 seconds and the true p99 is 0.26 seconds, the query returns something between 0.25 and 0.5, possibly 0.45 depending on how traffic sits inside the bucket. If your target is "99 percent under 300 milliseconds", 0.3 must be an exact bucket boundary.

When choosing buckets:

  • Make every target threshold (the numbers in your SLO) a bucket boundary.
  • Place boundaries densely in the range you care about and sparsely outside it. Exponential spacing, each bound roughly double the previous one, is a good start for latency.
  • Do not inflate the bucket count. Each bucket is a separate series per label combination. A fifteen-bucket histogram combined with twenty endpoints and five status classes turns one metric into thousands of series.

One more behavior to watch: if the quantile falls into the top +Inf bucket, the function returns the highest finite boundary. If your largest bucket is 10 seconds and requests time out at 30, your dashboard will show a p99 of "10 seconds" forever. Put the largest boundary above your timeout.

A better alert than a percentile: the fraction under a threshold

Percentiles are great on dashboards, but for alerts and service level objectives there is a sturdier measure: the fraction of requests served under a given threshold. A histogram gives you this exactly, with no interpolation:

sum(rate(http_request_duration_seconds_bucket{le="0.3"}[5m]))
/
sum(rate(http_request_duration_seconds_count[5m]))

This answers "what share of requests in the last five minutes completed under 300 milliseconds". Error budget math sits directly on this ratio: with a 99 percent target, the remaining one percent is your budget, and you alert on how fast it is burning. Unlike percentile-based alerts there is no estimation error from bucket width, because you are asking for an exact boundary.

There is a small trap: the le label value is matched as a string. The format your application exports and the format you write in the query must be identical. Look at the raw metrics endpoint to see how the bucket is actually written before you write the rule; an alert whose query returns an empty result never fires, and you will not notice.

Things that break the measurement itself

A correct query cannot save a wrong measurement. Common problems:

Starting the timer in the wrong place. If you start timing when your handler begins, the time the request spent waiting in a queue or a connection pool is never counted. Under overload, your measurement looks best exactly when the service is slowest. Measure as close to the outer edge as you can, at the load balancer or where the server accepts the request, and compare it with the internal timing.

Not separating errors. Fast error responses make the latency distribution look better. When a dependency goes down and the service returns a 503 in 2 milliseconds to every request, p99 drops. Keep the status class as a label and compute latency targets over successful requests.

Coordinated omission in load tests. If the load generator waits for a response before sending the next request, the requests that should have been sent while the server was stalled are never sent, and the stall barely shows up. A load test that generates requests at a fixed rate (an open model) reveals the real tail.

Short windows, few samples. If a one-minute window holds twenty requests, p99 is simply the slowest request. For low-traffic endpoints, widen the window or use the fraction under a threshold instead of a high percentile.

When you do not need all this

Putting a histogram on everything is also a mistake. For background workers, nightly batch jobs or tasks that run once a minute, recording each run's duration as a single value and watching the last run is usually enough. Where latency does not reach a user, the shape of the tail does not change decisions. Save histograms for the paths users wait on: request-serving endpoints and their critical dependencies.

A final note: newer Prometheus releases also offer native histograms that do not require predefined bucket boundaries. They largely remove the bucket selection problem, but they require support across the whole chain: client library, scraper and long-term storage. Check the documentation for the versions you run before switching; if one link in the chain does not support them, data may silently fall back to the classic format or not arrive at all.

The rule, in short: look at the distribution rather than the mean, aggregate buckets rather than percentiles, make your target threshold a bucket boundary, and build alerts on the fraction under that threshold.