What are the four Prometheus metric types, and what's the practical difference between a Histogram and a Summary?
Quick Answer
Counter (monotonically increasing, e.g. total requests), Gauge (can go up or down, e.g. current memory), Histogram (samples observations into configurable buckets, aggregatable across instances), and Summary (calculates quantiles client-side, cheaper to query but not aggregatable across instances). Histograms are almost always preferred for latency SLOs because you can aggregate them with histogram_quantile() across many pods; Summary quantiles are per-instance and mathematically invalid to average.
Detailed Answer
Counters only increase (or reset to 0 on restart) and are used with rate()/increase() to get per-second rates — never read a counter's raw value directly in a dashboard. Gauges represent a point-in-time value like queue depth or temperature and support any arithmetic.
Histograms bucket observations (e.g. request duration) into cumulative buckets defined by the le label (http_request_duration_seconds_bucket{le="0.5"}), plus a _sum and _count. Because the raw bucket counts are exposed, Prometheus's query engine can merge histograms from many instances and compute histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le)) for a fleet-wide p99 — this is the standard SLO pattern.
Summaries compute quantiles (e.g. p50, p99) inside the client library process before exposition, using a sliding time window. This is cheaper for Prometheus to store and query (no bucket explosion), but the resulting quantiles cannot be meaningfully averaged or summed across instances — a p99 of "5ms" on instance A and "50ms" on instance B do not combine into a fleet p99. For that reason most teams standardize on Histograms for anything that needs cross-instance aggregation and reserve Summary for single-instance-only stats.
Code Example
# Cross-instance p99 latency from a Histogram histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, service))
Interview Tip
Say explicitly "you cannot average Summary quantiles across instances" — this is the detail that separates people who've debugged a bad SLO dashboard from people reciting docs.