Video in progress
What is the difference between a histogram and a summary in Prometheus, and when do you pick which?
A histogram counts values into predefined buckets, and the quantile is computed on the Prometheus side and can be aggregated across instances. A summary computes the quantile inside the application: more precise, but results from several instances can't be combined correctly.
📖 Answer
A histogram comes out of the application like this:
http_server_requests_seconds_bucket{uri="/orders",le="0.1"} 940
http_server_requests_seconds_bucket{uri="/orders",le="0.25"} 990
http_server_requests_seconds_bucket{uri="/orders",le="+Inf"} 1000
p99 in Prometheus:
histogram_quantile(0.99,
sum by (le) (rate(http_server_requests_seconds_bucket{uri="/orders"}[5m])))
sum by (le) adds up the buckets of 10 pods and gives a correct p99 for the whole service.
A summary gives a ready number: {quantile="0.99"} 0.21. Each pod computed its own. Adding or averaging 10 p99s makes no mathematical sense.
| Histogram | Summary | |
|---|---|---|
| Where the quantile is computed | Prometheus | the application |
| Aggregation across instances | possible | not possible |
| Accuracy | depends on bucket boundaries | exact (within a configured error) |
| Changing the quantile later | yes, any one | no, fixed in code |
| Cost | each bucket is a separate series | few series |
In Micrometer: publishPercentileHistogram() emits histogram buckets, while publishPercentiles(0.95, 0.99) gives summary-style values computed inside the application.
In practice you almost always pick a histogram. A summary is appropriate only when there is a single instance or you need an exact number for that one process. In a histogram, the bucket count adds to cardinality, so enable it for the important metrics, not all of them.
Sign up to mark studied questions and save your progress.