Section650

Writing

TopicArchitecture
Reading7 min

Application Schema vs Reporting Schema: Why One Schema Can’t Do Both

Design the application schema for the application, run reporting on a read replica, and add a data warehouse only when you hit specific limits. One schema for both ends up bad at each.

By Ka Lun Chan · Architecture / Engineering judgment

Should your application schema double as your reporting schema?

No. Design the application schema for the application. Start reporting on a read-only replica with a BI tool such as Metabase, and add a data warehouse only when you hit specific limits. A single schema shaped for both jobs ends up bad at each one.

The temptation is understandable. The first reports usually come from the same people who built the app, the data is right there, and adding a few summary columns or a wide table for the dashboard feels faster than setting up anything new. It is faster, for a while. Then every feature migration has to think about the dashboard, and every heavy report competes with your users.

Here is the path I’d follow:

  1. Keep the app schema normalized and shaped by the domain and its transactions.
  2. Run early reports against production while they are small and rare.
  3. Move reporting to a read replica once it starts to affect the app.
  4. Add a warehouse when you need other data sources, history or many analysts.
Fig. 754-1 Where reporting should run, and the signal to move on
StageFits whenWhat it buys youMove on when
1. Query productionA few people, a few reports, small dataCheap and currentReports start slowing checkout, login or writes
2. Read replica + BI toolReports need to run often or scan months of dataKeeps heavy reads off the primaryCanceled queries, visible lag, or reports you can’t build from one database
3. Data warehouseSeveral sources, history, many analystsColumnar speed, joins across systems, stable modelsPipelines, modeling and cost become real work

Why do application and reporting workloads want different schemas?

An application writes small changes all day and needs each fact stored once, so it uses a normalized design. Reporting reads large amounts of data and aggregates it, so it works best with fewer joins and a denormalized star schema.

Application databases are usually normalized, often to third normal form (3NF). Each fact lives in one place, so an update touches one row and the database can enforce integrity with keys and constraints. ORMs map naturally onto that shape.

Reporting tools prefer a different model. Microsoft’s star schema guidance describes fact tables that store events, such as orders, with keys to dimension tables that describe them, such as customers, products and dates. It also says not to mix the two kinds of table. That shape answers business questions with a few predictable joins.

Using either shape for the other job hurts. CloudQuery’s comparison puts it plainly: a star schema as your application’s primary database creates write performance problems and makes integrity harder to enforce, while 3NF for analytics leaves analysts joining many tables to answer one question. Denormalized copies also mean the same value has to be updated in several places, which makes writes slower and easier to get wrong.

The workloads also change at different speeds. The app schema moves with every feature release. Reports need stable definitions, so last quarter’s revenue means the same thing next quarter. Tying the two together means either your releases slow down or your numbers drift.

There is a practical cost too. A report that scans a year of orders competes with checkout and login for CPU, memory and disk on the same server. If you’ve ever watched pages time out while someone ran a big export, you’ve seen it.

When should reporting move off the production database?

When reporting starts to slow down the app. Until then, querying production is fine. After that, use a read replica, and move to a warehouse when you need to combine data sources, keep history or support many people querying.

Basedash’s guide gives the order most teams end up following: run analytics on production for as long as you can, add a read replica when analytical queries start to slow product writes, and move to a warehouse when you need to join production data with tools such as Stripe or HubSpot, when transformations become routine, or when many people need to query without breaking anything.

The point of staging it is to pay for complexity only when the problem is real. A warehouse brings pipelines, modeling and its own bill. For a small team with a handful of dashboards, a replica and a few views will carry you a long way.

Data size alone is a weak trigger. MotherDuck frames its guidance on outgrowing Postgres for analytics around companies with roughly 10GB to 1TB of data, which is a useful range to keep in mind, not a line you cross on a particular day. The workload matters more than the number: how often reports run, how much history they scan, and how many people run them.

What does a read replica fix, and what doesn’t it fix?

A replica keeps heavy reads away from the primary. It doesn’t give you joins with other systems, long history, transformations or a reporting-friendly shape, because it’s an exact copy of the application database.

That exactness cuts both ways. A PostgreSQL streaming replica copies the whole server from the write-ahead log, so schema changes arrive automatically. The PostgreSQL docs note that this kind of replication can only be done for the entire server. You can’t add reporting tables or indexes to the replica alone.

Long reports on a replica can also be canceled. The hot standby documentation explains that a query on the standby is canceled when it conflicts with changes being replayed from the primary for longer than max_standby_streaming_delay. Turning on hot_standby_feedback reduces those cancellations, but it delays cleanup on the primary and can cause table bloat there. If your reports keep getting canceled, or the replica keeps falling behind, that’s a sign you’ve outgrown it.

One correction to advice that circulates widely: it’s logical replication, not the usual read replica, that leaves schema changes behind. The logical replication restrictions say the schema and DDL commands are not replicated, so a separate reporting database fed that way needs each relevant migration applied by hand. That’s worth knowing before you choose it.

How should you design the app schema so reporting is easy later?

Design it for the domain and keep a few habits that make history recoverable: timestamps on every table, status history where the business cares about it, and soft deletes for records people report on. Give reporting its own shape on top instead of changing the app tables.

  • created_at and updated_at on every table. Most reports start with “how many, over what period.”
  • A status history table for things that move through states, such as orders or tickets, when the business needs to know when each change happened. A single status column only tells you where something is now.
  • Soft deletes, such as a deleted_at column, for records that reports count. A hard delete removes the history.
  • Consistent names and money stored as integer cents or a decimal type, never as floats. I covered naming in plural or singular API and table names.

When reports need a different shape, build it beside the app tables, not inside them. Reporting views or materialized views in their own schema work well on a single database or a separate reporting database:

A reporting materialized view on top of normalized tables (PostgreSQL)
-- The app tables stay normalized. Reporting gets its own shape on top.
CREATE MATERIALIZED VIEW reporting.daily_orders AS
SELECT
  date_trunc('day', o.created_at) AS order_day,
  c.region,
  count(*)                        AS orders,
  sum(o.total_cents) / 100.0      AS revenue
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.status <> 'cancelled'
GROUP BY 1, 2;

-- Refresh on a schedule. CONCURRENTLY keeps the view readable during the
-- refresh, but needs a unique index on the view.
CREATE UNIQUE INDEX ON reporting.daily_orders (order_day, region);
REFRESH MATERIALIZED VIEW CONCURRENTLY reporting.daily_orders;

Later, the same definitions can move into a warehouse model with little change. The app tables never had to bend for a dashboard. If reports are slow even on the replica, look at the queries before buying more infrastructure. Don’t stop paying attention to SQL query performance covers how to find the expensive ones, and database performance and caching covers what to do about read load.

Sources

Checked in November against the PostgreSQL documentation, Microsoft’s star schema guidance, CloudQuery’s 3NF and star schema comparison, Basedash’s guide on when to add a warehouse and MotherDuck’s guide on outgrowing Postgres for analytics. The vendor guides are rules of thumb, not benchmarks. The stages table, the design checklist and the example are mine.

Short answers

Should the application schema also be the reporting schema?

No. Applications need a normalized schema so each fact is stored once and writes stay safe. Reporting works best with a denormalized star schema that needs fewer joins. A single schema shaped for both ends up bad at each, so keep the app schema for the app and give reporting its own shape on top.

When should reporting move off the production database?

When reports start slowing down the app, such as checkout, login or writes. Until then, querying production is fine. Then move reporting to a read replica, and add a data warehouse when you need to combine other data sources, keep history or support many people querying.

Does a PostgreSQL read replica copy schema changes?

A streaming read replica does, because it copies the entire server from the write-ahead log. Logical replication does not: the PostgreSQL docs say the schema and DDL commands are not replicated, so migrations must be applied to the subscriber by hand.

What should an application schema include to make reporting easier later?

Created and updated timestamps on every table, a status history table for records that move through states, soft deletes for records that reports count, consistent names, and money stored as integer cents or a decimal type. Build reporting views or materialized views beside the app tables instead of changing them.

Check where your reports run

List the reports and dashboards that query your production database, note how long each runs, and move the heaviest one to a replica or a materialized view first. That one change tells you whether you need anything bigger.

Tell me what you’re building