What is the difference between a histogram and a summary in Prometheus?
Prometheus histogram vs summary: where quantiles are computed, aggregatability across instances, accuracy, and which to pick for latency SLOs.
Expected Interview Answer
A histogram buckets observations into configurable ranges and exposes cumulative counts so quantiles are calculated at query time on the server, while a summary calculates streaming quantiles inside the client at scrape time and exposes those precomputed values directly.
Because a histogram ships raw bucket counts (_bucket, _sum, _count), its data is aggregatable across instances with histogram_quantile() and PromQL can derive any percentile later, at the cost of accuracy bounded by bucket boundaries. A summary computes φ-quantiles locally over a sliding time window, giving precise per-instance percentiles but values that cannot be meaningfully aggregated across multiple targets. Histograms are usually preferred for latency SLOs because they aggregate; summaries suit cases where a single instance needs an exact quantile cheaply.
- Histograms are aggregatable across instances and jobs
- Histograms let you compute any quantile after the fact in PromQL
- Summaries give precise per-instance quantiles without server computation
- Histograms enable Apdex and SLO burn-rate queries
- Choosing correctly avoids misleading percentile numbers
AI Mentor Explanation
Think of tracking a bowler's delivery speeds all season. A histogram is like grouping every ball into speed bins on a chart — under 120, 120-130, 130-140 kph — so anyone can later ask what the 90th-percentile pace was across all matches. A summary is the bowler's own coach writing down a single precomputed 'top 10% speed' number per game, precise for that match but impossible to correctly merge across the whole tournament.
Step-by-Step Explanation
Step 1
Understand what each records
Histogram counts observations per bucket and exposes _bucket, _sum, _count; summary computes streaming quantiles and exposes {quantile} series plus _sum and _count.
Step 2
Compare where quantiles are computed
Histogram quantiles are computed at query time via histogram_quantile(); summary quantiles are computed client-side at scrape time.
Step 3
Weigh aggregatability
Histogram buckets sum across instances so cross-target percentiles are valid; summary quantiles cannot be aggregated across instances.
Step 4
Weigh accuracy vs cost
Summaries are exact per-instance but pin the quantiles you chose; histograms trade bucket-bounded accuracy for query-time flexibility.
Step 5
Choose for the use case
Prefer histograms for latency SLOs and dashboards spanning many instances; use summaries for exact single-instance quantiles.
What Interviewer Expects
- Where quantiles are computed for each type
- Why summaries cannot be aggregated across instances
- The exposed time series for each type (_bucket, _sum, _count, {quantile})
- Use of histogram_quantile() on histograms
- A sound recommendation for latency SLOs
Common Mistakes
- Claiming you can average summary quantiles across instances
- Thinking histograms give exact percentiles regardless of buckets
- Confusing _sum/_count roles between the two types
- Forgetting histogram_quantile() operates on _bucket series
- Recommending summaries for multi-instance latency SLOs
Best Answer (HR Friendly)
“A histogram sorts measurements into ranges and lets the server work out percentiles later, and its data can be combined across many machines. A summary works out the exact percentiles on each machine as data arrives, which is precise but can't be safely combined across machines. Histograms are usually the safer choice for latency dashboards.”
Code Example
histogram_quantile(
0.95,
sum by (le) (rate(http_request_duration_seconds_bucket[5m]))
)http_request_duration_seconds{quantile="0.95"}Follow-up Questions
- How does histogram_quantile() interpolate within a bucket?
- What is a native (sparse) histogram in newer Prometheus versions?
- Why can't you aggregate summary quantiles across targets?
- How do you choose bucket boundaries for a histogram?
- What are _sum and _count used for beyond quantiles?
MCQ Practice
1. Where are quantiles computed for a Prometheus summary?
Summaries compute streaming quantiles client-side over a sliding window and expose them directly.
2. Which function derives a percentile from a histogram?
histogram_quantile() estimates a percentile from cumulative _bucket series.
3. Which metric type aggregates correctly across many instances?
Histogram buckets are additive across instances, so cross-target percentiles are valid; summary quantiles are not aggregatable.
Flash Cards
Histogram exposes which series? — _bucket (cumulative per le), _sum, and _count.
Summary exposes which series? — Precomputed {quantile=...} series plus _sum and _count.
Which type is aggregatable across instances? — Histogram — buckets sum; summary quantiles do not aggregate.
Which function computes histogram percentiles? — histogram_quantile(phi, rate(..._bucket[range])).
When prefer a summary? — When you need an exact per-instance quantile cheaply and won't aggregate it.