{"canonical_url":"https://engineer.company/glossary/histogram/","content_markdown":"# Histogram\n\n## What it is\n\nA histogram represents the distribution of observed values by counting how many\nobservations fall into ranges. For a service measuring request duration, the\nranges might separate events that finish within a few milliseconds from ones\nthat take much longer. The counts show where the observed workload spends its\ntime and let operators estimate properties of the distribution.\n\nRepresentations differ between systems. A classic Prometheus histogram exposes\ncumulative bucket counts. The count for a boundary includes observations at or\nbelow it. An aggregate count and sum can describe the number of observations and\ntheir mean. Other representations use disjoint buckets or a different choice of\nintervals. Read the measurement's format before combining counts or interpreting\na displayed value.\n\nA percentile such as the 95th percentile describes a point near the upper end of\nthe distribution. When it is calculated from histogram buckets, its precision\ndepends on the ranges and the estimation method. A count at an existing boundary\ncan directly show how many observations met that particular threshold. Choose\nboundaries and measurements that answer the questions users and operators need\nto ask.\n\n## Why it matters\n\nA mean can hide the experience of a smaller part of the workload. Suppose most\nrequests finish quickly while a few take several seconds. The average can look\nacceptable to an operator while the slow requests matter to the people who made\nthem. A histogram helps reveal how frequent the slow work is and how the\ndistribution changes during a release or incident.\n\nHistograms also support comparison across replicas when their observations use a\ncompatible measurement. Counts can be aggregated across replicas before\nestimating a percentile for the combined workload. An average of the percentiles\ndisplayed separately for each replica cannot generally describe that combined\ndistribution. Give the aggregation a documented population, compatible\nboundaries and a shared unit of time.\n\nStorage and query cost matter. Each classic bucket can contribute its own time\nseries for every combination of labels. Finer intervals give more information\nnear a performance threshold and also require more resources. Keep the number of\nboundaries and labels tied to the decisions the data supports. Monitor the cost\nwhere a histogram is used on a high-traffic route or many application instances.\n\n## What it looks like in practice\n\nImagine an API with a target response time of 250 milliseconds. Record\nserver-side duration at a well-defined request boundary and include a bucket at\nthat target. Populate a test interval with one hundred completed requests. If 93\nare inside the bucket, the share meeting the deadline is 93 percent for that\ninterval. Give the number of requests and the measured interval alongside the\nratio. A few measurements in a quiet period are easier to interpret when their\npopulation is visible.\n\nAdd representative slow requests and compare the bucket counts and percentile\nestimates. Check that the result changes at the expected boundary. If a\ndashboard estimates a percentile between two widely spaced boundaries, label its\nprecision appropriately or record narrower intervals near the relevant\nthreshold. Place enough boundaries around the latency values that matter to the\nperformance decision, and record the limits of the resulting estimate.\n\nEngineer's\n[Grafana and Prometheus monitoring case study](/portfolio/cut-operational-risk-with-grafana-and-prometheus/)\ndescribes instrumenting services, choosing meaningful metrics and using\nactionable alert thresholds. A latency histogram can support that approach when\na team wants to observe more than a mean. The example here ties one threshold to\nan explicit count so operators can connect an alert to the distribution of real\nrequests.\n\nTest a service split across different replicas as well. Feed the replicas\ndifferent numbers of requests and assign deliberately different latency\ndistributions. Reproduce the combined result from the bucket readings. This\nexercise confirms that the query respects the number of observations from each\nreplica and shows how an accidental unweighted average could mislead a reader.\n\n## Where it goes wrong\n\nA histogram can measure a different part of an operation from what users\nexperience. An internal handler may record only the time after a request leaves\nits queue. A mobile client can wait much longer for a completed result. State\nthe boundary and units in the metric's definition and pair it with another\nmeasurement when the missing part matters. Verify the chosen timestamp or timer\nthrough the actual entry point.\n\nCombining incompatible layouts can produce misleading results. If a release\nchanges bucket boundaries or a component starts reporting in different units,\ncheck which observations the aggregate query uses during the transition. A test\ncan read known samples before and after the change and verify a documented\nresult. Keep aggregation rules explicit, particularly when old and new process\nversions run at once.\n\nA running counter also needs a meaningful interval. In a typical monitoring\nsystem, a calculation uses changes in bucket counts over time and handles the\nreset that occurs when a process restarts. A single cumulative reading can\ncontain requests from long before the incident. Pick a window that reflects the\ndecision and test a restart during it. Compare the bucket changes and total\ncount with a known group of requests around that restart, so the display has\nevidence from the period people are investigating.\n\nFinally, check sparse traffic and missing samples. A percentile from one request\nsays something about that request and little about a wider population. A graph\nwith no measurements also needs a clear representation. Include counts and\nmeasurement state in dashboards and incident reports. A histogram is useful when\nthe team can explain what was counted and how the resulting estimate supports a\nparticular decision.\n\n## Further reading\n\n- [Prometheus guidance on histograms and summaries](https://prometheus.io/docs/practices/histograms/).\n  Explains bucket design and how distributions can be aggregated.\n- [Prometheus histogram quantile functions](https://prometheus.io/docs/prometheus/latest/querying/functions/#histogram_quantile).\n  Documents quantile calculation and boundary behaviour.\n- [OpenTelemetry metric aggregation](https://opentelemetry.io/docs/specs/otel/metrics/sdk/#aggregation).\n  Describes how observations can be combined in an SDK.\n\n\u003chttps://engineer.company/glossary/histogram/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"Record latency in buckets and see which counts you can aggregate before estimating an upper percentile.","formats":{"gemtext":"https://engineer.company/glossary/histogram/index.gmi","gopher":"https://engineer.company/glossary/histogram/gophermap","html":"https://engineer.company/glossary/histogram/","json":"https://engineer.company/glossary/histogram/index.json","markdown":"https://engineer.company/glossary/histogram/index.md","pdf":"https://engineer.company/glossary/histogram/index.pdf"},"kind":"page","language":"en","title":"What is a histogram?","url":"https://engineer.company/glossary/histogram/","version":1}