Quick revision
The short answer
A client-side percentile is calculated inside each instance and exported as a finished number, so p99 values from 30 instances cannot be combined into a true p99 for the whole service. A percentile histogram exports bucket counters instead, which the backend can add up across instances before it calculates the percentile. For p99 per endpoint across 30 instances, we enable the histogram for http.server.requests and compute p99 in the backend, for example with histogram_quantile in Prometheus.
What to remember
In this answer, we saw that client-side percentiles are computed inside each JVM and exported as final numbers, which cannot be combined across 30 instances because percentiles do not add up. Percentile histograms export bucket counters that the backend can sum and then turn into any percentile. For a service-wide p99 per endpoint, we enable management.metrics.distribution.percentiles-histogram.http.server.requests=true and use the backend's quantile function, while limiting histograms to important timers and narrowing their bucket range to keep the number of series reasonable.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A client-side percentile is calculated inside each instance and exported as a finished number, so p99 values from 30 instances cannot be combined into a true p99 for the whole service. A percentile histogram exports bucket counters instead, which the backend can add up across instances before it calculates the percentile. For p99 per endpoint across 30 instances, we enable the histogram for http.server.requests and compute p99 in the backend, for example with histogram_quantile in Prometheus.
Why this question is asked
Latency targets are almost always written as percentiles: 99 percent of checkout requests must finish within 400 ms. When a service runs on many instances, the way we collect that number decides whether it is correct or quietly wrong, and a wrong p99 on a dashboard leads to wrong decisions during an incident. Interviewers ask this because many teams turn on publishPercentiles, see a nice line on the dashboard, and never notice that it cannot be aggregated. In this answer, we will recap what a Micrometer timer records, look at how client-side percentiles are computed and why they break when we combine instances, see how histograms avoid the problem, and then configure the right option in Spring Boot while keeping the number of time series under control.
1A Quick Recap of Micrometer Timers
Micrometer is the metrics library that Spring Boot uses. A timer is a meter, a named measuring instrument, that records how long something took. Every time a request finishes, the timer adds one sample. By default a timer exports three numbers per time series: a count of samples, the total time of all samples, and the maximum seen recently. From count and total the backend can draw an average, but not a percentile.
A percentile, such as p99, is the value below which 99 percent of samples fall. If p99 is 800 ms, one request in a hundred took longer than 800 ms. To know that, somebody must look at the distribution of samples, not just their sum. Micrometer offers two ways to do that, and they differ in where the calculation happens.
2How Client-Side Percentiles Are Computed
With publishPercentiles(0.99), Micrometer keeps a small decaying histogram in the application's memory and calculates the 99th percentile itself. It then exports that ready-made value as a gauge with a phi tag (quantile="0.99" in Prometheus). The calculation is done on the client, meaning inside our service, which is where the name comes from.
This is cheap for the backend and works with any monitoring system, even one that knows nothing about histograms. But notice what leaves the instance: only the final number. The raw samples, and the information about how many requests stood behind that number, are gone.
3Why Percentiles From 30 Instances Cannot Be Combined
Suppose 29 instances are healthy with a p99 of 100 ms each, and one instance has a slow disk with a p99 of 2,000 ms. The real p99 of all requests depends on how many requests each instance served and what their full distributions look like. Taking the average of the 30 values gives about 163 ms. Taking the maximum gives 2,000 ms. Neither is the real answer, and there is no formula that can recover it from the 30 numbers alone.
The reason is that percentiles are not additive. A sum or a count from two instances can be added; a percentile of one group plus a percentile of another group is not the percentile of both groups. So any dashboard query like avg(http_server_requests_seconds{quantile="0.99"}) is showing a number that only looks like a p99.
| Aspect | Client-side percentiles | Percentile histogram |
|---|---|---|
| Where p99 is computed | Inside each instance | In the backend, at query time |
| What is exported | One gauge per chosen percentile | One counter per latency bucket |
| Can be aggregated across instances | No | Yes, by summing buckets |
| Choose another percentile later | No, fixed in code | Yes, any percentile in the query |
| Series cost per tag combination | Small: one per percentile | Larger: one per bucket |
There is a second, smaller catch. Client-side percentiles decay over a time window configured inside the application, so two instances may even be reporting over slightly different windows. Client-side percentiles are still useful for a single instance, for example when we debug one JVM, but not for a service-wide target.
4How Histograms Solve It
With publishPercentileHistogram(), Micrometer does not compute a percentile at all. It keeps counters for a set of latency buckets, for example how many requests took at most 10 ms, at most 50 ms, at most 100 ms, and so on. In Prometheus these appear as series ending in _bucket with an le label, which means less than or equal.
Counters can be added. The backend sums the bucket counters from all 30 instances, which gives one combined distribution for the whole service, and then estimates the percentile from that combined distribution. The estimate is as precise as the bucket boundaries allow, and Micrometer's default boundaries are fine enough for latency work.
Notice the order of the operations: first rate() per series, then sum by le and uri, which removes the instance label, and only then histogram_quantile. Summing first is the whole point. Other backends have the same idea under different names, so check the quantile function of the system you use.
5Configuring It in Spring Boot
For the HTTP server timer that Spring Boot creates for us, we do not touch code. We turn the histogram on with a property whose last part is the meter name. The property also accepts a prefix, so http.server.requests covers exactly that meter and its children.
For our own timers we call publishPercentileHistogram() on the builder. Keep in mind that the histogram is not free. Every bucket is its own time series, and the default histogram for a timer has several dozen buckets. With 40 endpoints, 5 status values, 2 methods and 30 instances, multiplying by roughly 70 buckets turns 12,000 series into well over 800,000. So we enable histograms for the timers that carry a latency target, narrow the expected range so fewer buckets are created, and for less important timers use slo boundaries, which export only the few buckets we really need.
6Follow-up questions
Can we use both percentiles and a histogram on the same timer?
Yes. Micrometer will export the client-side gauges and the buckets side by side. It can help when a team wants a quick per-instance view while the service-wide p99 comes from the buckets, but it doubles the confusion if dashboards mix them. Most teams pick histograms for anything that is aggregated and drop the client-side percentiles.
How accurate is a percentile estimated from buckets?
The backend assumes samples are spread evenly inside a bucket, so the result can be off by up to the width of the bucket that holds the percentile. With Micrometer's default boundaries, which grow gradually, the error is small for typical web latencies. If an SLO boundary such as 400 ms matters, adding it as an slo bucket makes the answer at that boundary exact.
What about backends with native or exponential histograms?
Newer Prometheus versions and OTLP support exponential histograms that adapt their buckets and are cheaper per series. Micrometer's OTLP registry can send them, and Prometheus native histogram support has been growing. The principle is the same: export a mergeable distribution, compute percentiles in the backend. Check your Micrometer and backend versions before relying on them.
7Conclusion
In this answer, we saw that client-side percentiles are computed inside each JVM and exported as final numbers, which cannot be combined across 30 instances because percentiles do not add up. Percentile histograms export bucket counters that the backend can sum and then turn into any percentile. For a service-wide p99 per endpoint, we enable management.metrics.distribution.percentiles-histogram.http.server.requests=true and use the backend's quantile function, while limiting histograms to important timers and narrowing their bucket range to keep the number of series reasonable.
Open with
Client-side percentiles, from publishPercentiles, are calculated inside each instance and exported as a gauge. That's fine for looking at one JVM, but percentiles don't add up, so if I have 30 instances there's no correct way to combine 30 p99 values.
Then, if they want more
Averaging them hides a slow instance and taking the max exaggerates it. A percentile histogram, from publishPercentileHistogram, exports counters per latency bucket instead. Counters can be summed, so the backend adds the buckets from all 30 instances and then estimates the percentile from the combined distribution.
In Prometheus that's histogram_quantile of 0.99 over sum by le and uri of the rate of the bucket series. So for p99 per endpoint across the fleet, I'd turn on management.metrics.distribution.percentiles-histogram.http.server.requests=true and compute it in the backend.
The cost is cardinality: every bucket is a time series, and a timer has several dozen buckets by default, multiplied by every tag combination and every instance.
So I enable histograms only for timers that carry a latency target, narrow the range with minimum and maximum expected value, and for other timers I use a few SLO boundaries instead of the full histogram.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Cloud documentation, Resilience4j documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain the difference between client-side percentiles and histograms in Micrometer...": https://scrivio-interview-library.netlify.app/spring-boot/observability/6020ac4bca/