Course contentsShow
← System Design
Lesson 1176 of 1,91930. Observability: MetricsFree lesson

Histogram Metrics

Understand histograms as bucketed distributions of values, useful for latency and size measurements.

Histogram Metrics

You'll learn how histograms capture the distribution of values, revealing patterns that single-number metrics miss.

What Is a Histogram?

A histogram metric groups measurements into predefined buckets (ranges) and counts how many observations fall into each bucket. Unlike counters that just increment or gauges that show a single current value, histograms reveal the distribution of your data over time.

Think of it like sorting exam scores: instead of just knowing the average grade (which could be 75%), you see that 10 students scored 60-70%, 50 students scored 70-80%, 30 students scored 80-90%, and 10 scored 90-100%. This distribution tells you far more than the average alone.

Why Histograms Matter

Histograms excel at tracking latency (request duration) and size measurements (payload bytes, batch sizes). They answer questions like:

  • "What percentage of requests complete under 100ms?"
  • "Are my P95 and P99 latencies acceptable?"
  • "Is my upload size distribution skewed toward large files?"

For example, if your average request latency is 200ms, that might seem fine—but a histogram could reveal that 90% complete in 50ms while 10% take 2+ seconds. That's a problem the average hides!

How They Work

You define buckets beforehand (e.g., 0-10ms, 10-50ms, 50-100ms, 100-500ms, 500ms+). Each measurement increments the appropriate bucket's counter. Many systems also track the total count and sum, letting you calculate averages alongside distributions.

Unlike logs that store every value, histograms pre-aggregate data efficiently, making them lightweight even for millions of requests.

Key Takeaway: Histograms bucket measurements into ranges, exposing distribution patterns critical for understanding latency percentiles and size variability—information that averages and single values cannot reveal.