Skip to content
← All writing

Block decomposition: how ClickHouse, Prometheus, and InfluxDB rediscovered the same fundamental algo

  • Algorithms
  • Databases
  • Time-series
Diagram of a sequence partitioned into highlighted decomposition blocks

Published on HackerNoon. Read the full article.

Square-root decomposition is a staple of competitive programming: split the data into fixed-size blocks, keep a summary for each block, and answer range queries by skipping the blocks you do not need. This article shows that three major time-series databases arrived at the same shape independently:

  • ClickHouse MergeTree uses 8,192-row granules with sparse marks and min/max skip indexes.
  • Prometheus TSDB groups 120-sample chunks into two-hour blocks whose metadata records min and max timestamps.
  • InfluxDB partitions data into time-based shards whose TSM files store offsets, lengths, and timestamp metadata.

In all three, block size is the tuning knob: it trades pruning accuracy against scan throughput. The article also looks at where the model breaks, such as single-row lookups and two-dimensional filtering by time and labels, and how to use the idea when designing your own storage.