How Prometheus Finds Matching Series in Milliseconds
Picture the situation. You ask Prometheus for one specific label combination. Behind the scenes it is sitting on ten million active time series. The answer comes back in a few milliseconds. The interesting part is that it never looked at all ten million series to find it, and it decided which series to skip without reading them either. That gap, between how much data exists and how little of it a…
Prometheus quickly finds matching series in just milliseconds by using an inverted index data structure. Instead of checking each series against a specific label combination, Prometheus maps each label=value pair to a sorted list of series IDs that match. This allows it to answer queries by simply intersecting the sorted lists of IDs, which requires only a linear pass and binary searches, rather than scanning all ten million series.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.