Home›Design›Analytics and reporting
Design doc · Analytics and reporting

Analytics, dashboards and reporting

Where should reports and dashboards run, so they do not slow down the application?

Applications like this: business dashboards, finance reports, product analytics. This page is written the way I write a database design doc: the workload first, then where each kind of data goes and why, then how it grows, what breaks, and what I rejected.

The short answerNot on the production primary. Copy data to a column store (ClickHouse, BigQuery, Redshift, Snowflake, DuckDB for small cases) through change data capture or batch loads, and run reports there.
1 · The workload

What the application asks of the database

DimensionThis application
WritesBatch loads or a stream of changes from production.
ReadsBig scans with aggregates over a few columns.
Read to writeReads are few but each one reads a lot.
ConsistencyMinutes behind production is usually fine.
LatencySeconds for a dashboard, minutes for a heavy report.
GrowthLarge. All history, often from several systems.
Connected

Real failures behind this design

These incidents are why the choices below matter. Each one is written up with its numbers and sources.

2 · What goes where

Each kind of data, its store, and why

ApplicationFact tables (orders, events)A column storeCOPYThe application dataStays in the OLTP databaseSOURCE OF TRUTH

Solid arrows: the application writes there. Dashed arrows: a copy fed from the source of truth (change data capture, an outbox, or a cache fill), which can be rebuilt from it.

DataWhere it goesWhy
Fact tables (orders, events)A column storeReads only the columns a query names, compressed, in parallel.
The application dataStays in the OLTP databaseThe copy must never be able to slow the source down.
The pipelineChange data capture (Debezium, or the managed equivalent) or scheduled batch exportsShips ongoing changes without running scans on the primary (after a one-time snapshot).

How each family of store behaves under traffic: Database families.

3 · Data model

The core tables and the queries they serve

-- ClickHouse
CREATE TABLE order_lines (
  order_id    UInt64,
  created_at  DateTime,
  customer_id UInt64,
  sku         LowCardinality(String),
  qty         UInt32,
  price_cents UInt64
) ENGINE = MergeTree
PARTITION BY toYYYYMM(created_at)
ORDER BY (sku, created_at);

SELECT sku, sum(qty * price_cents) / 100 AS revenue
FROM order_lines
WHERE created_at >= now() - INTERVAL 30 DAY
GROUP BY sku ORDER BY revenue DESC LIMIT 20;
4 · How it grows

Start simple, change one thing at a time

  1. A read replica for reportsFine for small data. Long reports can conflict with replay on a PostgreSQL standby.
  2. Reports scan millions of rowsA column store fed by CDC or nightly loads.
  3. Many sourcesA warehouse or lakehouse with a modeling layer, and dashboards on top.

Scale it: watch this design grow

Pick a stage, then throw something at it. The numbers are a model to show the shape of each change, not a measurement; the measured numbers are in the lab notebooks.

5 · What breaks first

The failures to plan for

What happensWhat you seeWhat I do
Reports on the primaryThe application slows down at report timeMove them. This is the most common cause of mystery slowdowns on a schedule.
Single-row inserts into a column storeToo many small parts, merges fall behindBatch the inserts.
Replica used for both failover and heavy reportsA long query delays replay, and the failover target is behindSeparate the two roles.
6 · Alternatives

What I considered and did not pick

Cost. Warehouses bill by data scanned or by compute time. Partition and sort keys that match the common filters are the main lever.

How this page was writtenFrom the engines' documentation and common practice. Measured on real servers: a ClickHouse report over 10 million rows, and batch against single-row inserts, in the notebooks. Before you build: check the anti-patterns, size it with the capacity calculator, and write your own version from the design doc template. Want a second opinion? Submit it for review.
7 · Where to run it

On-prem, managed, EC2 or Kubernetes

StageWhere it runs
Where I would startA managed warehouse or ClickHouse Cloud, fed by CDC
When it growsThe same. Self-managed ClickHouse on VMs if scan costs are high and the team exists

For a team without a dedicated database team. Who does which job in each option, and the full-cost comparison: Where to run the database.

8 · Estimate it

The numbers, worked live

The back-of-the-envelope numbers I would want before choosing anything. Move the assumptions to match your application. The link keeps your numbers, so a colleague sees the same ones.

Part 3 of 4 · Design · 24 pagesAll pages

Which database does my application need? What kind of application data goes in which database, and why, as design docs, plus the anti-patterns and the decisions behind them.