At 02:10 the p99 panel for the checkout API jumps from 480 ms to exactly 1.000 s and sits there, flat as a ruler, for forty minutes. Nothing about real latency is that tidy. What you are watching is histogram_quantile doing what it was built to do: when the 99th percentile request lands in the bucket above 1 second, the function cannot see inside that bucket, so it reports the highest boundary it knows and stops.
That flat line is the most useful thing to understand about Prometheus percentiles. The number on the panel is an estimate built from bucket counts and one assumption, and the size of the error is set when someone picks the buckets, often months before the incident.
What the function does with your buckets
A classic Prometheus histogram is a set of counters. Each counter answers one question: how many observations so far were less than or equal to this value? You query them as series of a metric ending in _bucket, plus _sum and _count.
Bucket: a counter labelled le ("less than or equal"). The series with le="0.25" counts every request that took 0.25 seconds or less since the process started.
Cumulative: each bucket includes all smaller ones. The le="0.5" bucket contains everything in le="0.25" plus the requests between 0.25 and 0.5 seconds. The last bucket, le="+Inf", always equals _count.
φ (phi): the quantile you ask for, between 0 and 1. histogram_quantile(0.99, ...) asks for the value below which 99% of observations fall.
The function receives a set of bucket counts that share every label except le, sorts them by boundary, finds the bucket where the requested rank falls and interpolates inside it linearly. That last step is the assumption: observations are spread evenly between the lower and upper boundary of that bucket. Real latency rarely is. Requests cluster near cache hit times, near timeouts, near retry intervals, and the function has no way to know.
The default buckets in the Go client library are 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5 and 10 seconds. Between 1 and 2.5 seconds there is one bucket that is 1.5 seconds wide, so any p99 that lands there carries an uncertainty of up to 1.5 seconds before you have written a single line of PromQL.
The interpolation, worked by hand
Here is the formula the function applies once it has found the right bucket.
rank = phi x total_count
estimate = lower_bound + (upper_bound - lower_bound) x (rank - count_below) / count_in_bucket
where
count_below = cumulative count of the bucket before the one containing rank
count_in_bucket = cumulative count of this bucket - count_below
lower_bound = upper boundary of the previous bucket (0 for the first bucket, if its bound is positive)
An illustrative example. Over 5 minutes, rate() gives you these per-second counts, multiplied out to whole numbers for readability: 600 requests at or under 0.1 s, 850 at or under 0.25 s, 950 at or under 0.5 s, 990 at or under 1 s and 1,000 in total.
For p90, the rank is 0.9 x 1,000 = 900. The first bucket whose cumulative count reaches 900 is le="0.5" (950). The bucket below it holds 850, so count_below is 850 and count_in_bucket is 100. The estimate is 0.25 + 0.25 x (900 minus 850) / 100 = 0.25 + 0.125 = 0.375 seconds.
That 0.375 is plausible, but the real p90 could be anywhere between 0.25 and 0.5. If those 100 requests were bunched just above 0.25 s, the true value might be 0.27; if they were mostly slow retries near 0.48, the true value is close to 0.5. Same counts, same answer, very different reality.
For p99.5 the rank is 995, which is above the 990 in le="1". It lands in the +Inf bucket, which has no upper bound. Prometheus then returns the upper bound of the second highest bucket: exactly 1 second. That is the flat line from the opening scene.
Where the estimate goes wrong
Four situations produce most of the bad numbers people see on dashboards.
The quantile falls in the +Inf bucket. The function returns the highest finite boundary, which hides how bad things are. If your largest bucket is 1 second and your timeout is 30, a p99 of "1.0" may mean anything from 1 to 30 seconds.
The bucket is wide relative to what you care about. If your SLO threshold is 300 ms and your buckets jump from 0.25 to 0.5, every estimate in that range is a straight line drawn between two points. You will see a p95 of 0.31 and have no idea whether you are inside or outside the target.
The lowest bucket is too high. If the first boundary is 0.1 and most requests take 3 ms, the function assumes they were evenly spread from 0 to 0.1, so the p50 comes out around 0.05. That is about 16 times the real value.
The sample count is tiny. With 12 requests in a 5 minute window, a p99 is the slowest request, interpolated. It will jump around on every scrape, and an alert on it will flap. Use a longer range or a lower quantile when traffic is low.
The function also returns NaN when there are no observations in the window, and it needs the +Inf bucket present to work at all. If a relabelling rule or a recording rule drops that series, you get NaN or nonsense, and the panel shows a gap that looks like an outage.
Rate first, then sum by le, then quantile
Order of operations is the other common source of wrong percentiles. The correct shape for a service with several pods is:
histogram_quantile(0.95,
sum by (le) (rate(http_request_duration_seconds_bucket{job="checkout"}[5m]))
)
Each step has a reason. rate() comes first because bucket counters reset when a pod restarts, and rate handles resets per series; summing raw counters across pods mixes reset and non reset series. sum by (le) comes second because it merges the buckets of every pod into one histogram while keeping the le label the function needs.
If you write sum without by (le), the label disappears and the function has nothing to work with. If you want per route percentiles, keep that label too: sum by (le, route).
The tempting mistake is to compute a quantile per pod and then average the results, for example avg(histogram_quantile(0.95, rate(...[5m]))). An average of percentiles is not a percentile. A pod handling 10 requests with a p95 of 2 seconds gets the same weight as a pod handling 10,000 with a p95 of 0.2 seconds. Summing buckets first weights each request equally, which is what a percentile means.
The range in rate(...[5m]) matters too. It should cover at least 4 scrape intervals so a missed scrape does not empty the window. With a 30 second scrape interval, 2 minutes is the practical minimum; 5 minutes is a common, safe default.
Histogram, summary or native histogram
Prometheus offers three ways to record a distribution. The choice decides what histogram_quantile can do for you later.
| Classic histogram | Summary | Native histogram | |
|---|---|---|---|
| Where quantiles are computed | Server side, at query time | Client side, in the application | Server side, at query time |
| Aggregate across pods | Yes, sum by le | No, quantiles cannot be combined | Yes, sum without le |
| Choose quantile later | Yes, any φ | No, fixed when you instrument | Yes, any φ |
| Accuracy | Limited by bucket layout | Configurable error per quantile | High, exponential buckets |
| Series per metric | One per bucket, often 10 to 15 | One per quantile plus sum and count | One per series, buckets inside |
| Setup cost | Pick buckets carefully | Pick quantiles and error | Feature flag on older versions, newer client libraries |
Summaries look attractive because they report a precise p99 from each process. The catch is that you can never combine them: the p99 of a whole service is not derivable from the p99 of each pod. For anything behind a load balancer, that rules them out for service level percentiles.
Native histograms, introduced as an experimental feature in Prometheus 2.40, use exponentially sized buckets chosen automatically, store them inside a single series and let histogram_quantile run without an le label. They fix the bucket layout problem for most cases. Check your Prometheus and client library versions and whether the feature flag is still needed before you plan a migration.
A latency SLO that looked broken
An illustrative case, composited from a common pattern. A payments team in Porto sets an SLO: 95% of authorisation requests under 300 ms. They chart histogram_quantile(0.95, ...) and alert when it goes above 0.3. The service uses the default Go buckets, so the relevant boundaries are 0.25 and 0.5.
Within a week the alert fires 11 times. Each time, the p95 panel shows something between 0.30 and 0.34, the team looks at traces, and the traces show most slow requests around 0.27 to 0.29 seconds. The alert is not wrong about the counts; it is wrong about the shape. Around 7% of requests sit in the 0.25 to 0.5 bucket, and linear interpolation spreads them evenly, pushing the estimate over 0.3.
The fix is two lines. They add a bucket boundary at exactly 0.3, and they change the SLO query from a percentile to a ratio:
sum(rate(auth_duration_seconds_bucket{le="0.3"}[5m]))
/
sum(rate(auth_duration_seconds_count[5m]))
That ratio is exact, because the boundary matches the threshold: it counts the share of requests at or under 300 ms with no interpolation. They alert when it drops below 0.95 over a 1 hour window and keep the p95 panel for humans. False alerts drop to zero in the following month, and the team stops arguing with its own dashboard.
Questions to ask before you trust a p99 panel
When a percentile on a dashboard drives a decision, run through these before acting on it.
Where are the bucket boundaries relative to the number you care about? If your threshold sits between two boundaries, the estimate around it is a guess. Add a boundary at the threshold.
Is the value suspiciously round or flat? A p99 that equals a bucket boundary for many minutes is almost always the +Inf case or a quantile landing exactly on a boundary. Check the top buckets directly.
How many observations are in the window? Divide _count rate by the range. Below a few hundred requests, a p99 says little.
Was the aggregation done in the right order? Look for averaged quantiles and for sum without by (le).
Do you need a percentile at all? For an SLO, the share of requests under a threshold is usually the better question, and with a matching bucket it is exact.
These questions are also a fair test of observability depth in an SRE or platform engineering interview; candidates who can explain the +Inf behaviour and the rate, sum, quantile order usually understand PromQL beyond copying dashboards. The tooling is moving their way. As native histograms spread through client libraries and exporters, the bucket design problem shrinks, and histogram_quantile will more often return something close to the real distribution. The interpolation assumption will not disappear, though; it will just move to finer buckets, where it costs less.