Aggregation tables with dbt metrics

Silja Märdla19 Mar 2025

Problem

On large data, aggregation comes before exposure: fewer rows make queries and reports faster. The price is lost flexibility. Bolt's analytics engineers wanted fast tables and on-the-fly queries from one definition per metric, without duplicating business logic, with governance and consistent numbers across the data lake, Looker and the experimentation platform.

Example from the article: Bolt serves rides metrics (revenue before and after discounts, activated users) by city and country at hour, date, week, month, quarter and year grains.

Solution in brief

Define every metric once in the dbt semantic layer, on the most granular fact table. Sort metrics into additive, ratio and distinct-count groups, because each group aggregates differently. Bolt generates one saved query per grain from a short input file, then builds incremental dbt models, YAML and a union table from it.

Questions this case answers
  • How to serve governed metrics at many aggregation grains from precomputed tables while each metric is defined only once and nested grains reuse coarser-level results
  • How to evolve a set of precomputed aggregation tables when metrics are added or retired, without full recomputation
  • How to pre-aggregate metrics for fast reporting while keeping a single definition of each metric?
  • How to produce the same metric set at dozens of grains (city, country, hour, month) without hand-maintaining dozens of queries?

Tools and methods

  • dbt semantic layer (MetricFlow) — semantic models, metrics and saved queries as the single metric definition
  • Saved queries — one metric set grouped by one set of dimensions, i.e. one aggregation grain
  • Generator script (in-house) — turns a grain list into saved queries, model YAML and SQL
  • Looker — BI layer; metric definitions are translated into it with Euno
  • Airflow, DataHub — orchestration and metadata in Bolt's stack
Continue reading — it's free

Google or a one-time email code. No password.