Quick revision
The short answer
I would separate the workloads. The OLTP cluster stays normalised and indexed for short product queries, and analytics moves to its own system fed by change data capture: a read replica as a first step, and for the join-heavy work a columnar warehouse or lakehouse, which handles wide joins and aggregations far better than row storage. Around that we define ownership and SLAs for the pipeline and its freshness lag, publish a small set of curated denormalised models so analysts stop writing 14-table joins, and budget compute per workload so a heavy report can never take the product down.
What to remember
In this answer, we saw that short OLTP queries and long join-heavy analytics fight over the same cache, CPU, memory and vacuum on one cluster. Read replicas relieve the primary but keep the same row storage and plan limits, so the long-term design separates workloads: CDC from logical replication into a columnar warehouse or lakehouse that handles wide joins and aggregations far better. We added clear ownership and freshness SLAs with an honest view of their cost, curated denormalised models so analysts stop writing 14-table joins, and per-workload compute budgets so a heavy report cannot hurt the product.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would separate the workloads. The OLTP cluster stays normalised and indexed for short product queries, and analytics moves to its own system fed by change data capture: a read replica as a first step, and for the join-heavy work a columnar warehouse or lakehouse, which handles wide joins and aggregations far better than row storage. Around that we define ownership and SLAs for the pipeline and its freshness lag, publish a small set of curated denormalised models so analysts stop writing 14-table joins, and budget compute per workload so a heavy report can never take the product down.
Why this question is asked
Most companies start with one PostgreSQL database that serves everything, and for years that is the right choice. Then analysts arrive, reports grow, and one day a quarterly query that joins a dozen tables pushes product latency from 20 ms to 2 seconds. Interviewers ask senior candidates this question to see whether they can name the underlying conflict and design a durable architecture with honest trade-offs, instead of adding indexes forever. In this answer, we will look at why the two workloads clash, consider read replicas and where they stop helping, design the separate analytics path with CDC and a columnar store, and then cover ownership, freshness, curated models and compute budgets.
1Why the Two Workloads Clash
OLTP, online transaction processing, is the product's workload: many short queries that read or write a few rows by key, such as load order 42 or insert a payment, each expected in milliseconds. Analytics is the opposite: few long queries that scan millions of rows, join many tables and aggregate, such as revenue per region per product line for the last year.
On one cluster they fight over the same resources. A 14-table analytical join reads gigabytes, evicting the hot pages product queries rely on from shared_buffers, so product reads suddenly go to disk. It uses CPU cores and work_mem for big hashes and sorts, and long-running transactions hold back vacuum, so tables bloat. Indexes added for analysts slow down every write. No amount of tuning removes the conflict, because the two workloads want different things from the same storage.
2Read Replicas: A Good First Step With Limits
The quickest relief is to send analytics to a streaming read replica, a copy of the database kept up to date from the primary's write-ahead log. The primary's cache and CPU are protected, and analysts keep the SQL they know.
But a replica has the same row storage, the same indexes and the same planner as the primary, so a 14-table join is just as slow there; it merely hurts someone else. Long analytical queries on a hot standby also conflict with replication: either they are cancelled when the primary's changes need to remove rows they still read, or, with hot_standby_feedback on, they hold back vacuum on the primary, which brings the bloat problem back. So a replica is a good step for moderate reporting, not the end state for heavy analytics.
3A Separate Analytics Path Fed by CDC
For the long term I would build an analytics path that does not share storage with the product. Change data capture, CDC, reads the primary's logical replication stream, so every insert, update and delete is captured without extra queries, and a tool such as Debezium publishes the changes to Kafka. From there they are loaded into a columnar warehouse or a lakehouse with open table formats.
Columnar storage keeps each column separately and compressed, so a query that sums revenue over 500 million rows reads only the columns it needs, often a tiny fraction of the bytes a row store would read, and its engine is built for big parallel scans, hash joins and aggregations. A join that takes 20 minutes on the OLTP schema can take seconds there. The product database no longer sees analytical queries at all.
- Product servicesshort queries by key, millisecond SLAs
- OLTP PostgreSQL primarynormalised, indexed for product access paths
- CDC from logical replicationDebezium or similar, changes to Kafka
- Columnar warehouse or lakehouseraw tables plus curated models
- Analysts and BI dashboardsown compute budget, freshness SLA
5 layers, from the top down. Step through them one at a time.
The product database serves product queries only; analytics reads its own copy.
4Ownership, SLAs and the Cost of Freshness
A pipeline that nobody owns breaks quietly. So a named data platform team owns CDC and loading, with SLAs on freshness, for example 95% of changes visible in the warehouse within 5 minutes, and on availability. Schema changes in product services become a contract: a migration that renames a column must not silently break the pipeline, so CDC events are checked against a schema registry and breaking changes are reviewed.
Freshness has a price. Near-real-time loading needs streaming infrastructure running all the time, while hourly or daily batches are much cheaper. Most analytics is fine with an hour or even a day of lag; a few operational dashboards may need minutes. Agreeing on this per use case avoids paying for real time everywhere.
5Curated Models Instead of Fourteen-Table Joins
If every analyst reconstructs revenue from raw normalised tables, we get slow queries and, worse, different answers to the same question. So the data team publishes a small set of curated, denormalised models: an orders fact table already joined with customer, region and product attributes, daily aggregates per region, and similar. Tools such as dbt can build and test these models in the warehouse. Analysts query the models; the 14-table join is written once, reviewed and tested, instead of a hundred times.
6Budget Compute per Workload
Finally, even in the warehouse one heavy query should not starve the rest. Warehouses let us assign separate compute pools or resource groups, for example one for scheduled reporting, one for ad hoc analysis and one for dashboards, each with its own limits and query timeouts. On the OLTP side, whatever reporting remains on the primary or a replica gets its own database role with statement_timeout and a connection limit. The guarantee we want is structural: by design, no report can take the product down.
7Follow-up questions
How fresh must the analytics data be, and what does that cost?
It depends on the decision the data supports. Finance and product analytics are usually fine with hourly or daily data, which cheap batch loads provide. Operational dashboards, such as live order volume or fraud monitoring, may need minutes, which means continuous CDC streaming and a warehouse that ingests continuously, with higher infrastructure and on-call cost. I would agree freshness per use case, publish it as an SLA, and only pay for streaming where a real decision needs it.
Why not just make the OLTP database bigger?
A bigger server buys time but does not remove the conflict: analytical scans still evict product data from cache, still compete for I/O and CPU, and still hold back vacuum. Costs also rise steeply at the top end, while the analytics workload keeps growing. Separating workloads lets each system be sized and tuned for its own job.
What does CDC add in risk to the product database?
Logical replication slots keep write-ahead log until the consumer has read it, so if the CDC pipeline stops, WAL accumulates on the primary and can fill the disk. We monitor slot lag, alert early, and set max_slot_wal_keep_size so a broken consumer cannot take the primary down.
8Conclusion
In this answer, we saw that short OLTP queries and long join-heavy analytics fight over the same cache, CPU, memory and vacuum on one cluster. Read replicas relieve the primary but keep the same row storage and plan limits, so the long-term design separates workloads: CDC from logical replication into a columnar warehouse or lakehouse that handles wide joins and aggregations far better. We added clear ownership and freshness SLAs with an honest view of their cost, curated denormalised models so analysts stop writing 14-table joins, and per-workload compute budgets so a heavy report cannot hurt the product.
Open with
The root problem is two workloads with opposite needs on one cluster. Product queries are short lookups by key with millisecond expectations; analytics scans and joins millions of rows.
Then, if they want more
On one database the analytics evicts the product's hot pages from cache, takes CPU and memory for big hashes and sorts, and long transactions hold back vacuum. So I would separate them.
As a quick step, a read replica protects the primary, but it has the same row storage and planner, so a 14-table join is still slow, and long queries on a standby either get cancelled or hold back vacuum through feedback.
The long-term design is change data capture from logical replication, for example Debezium into Kafka, feeding a columnar warehouse or lakehouse. Columnar engines read only the needed columns, compressed, and are built for big scans, joins and aggregations, so these queries become seconds and the product database never sees them.
Around that I would set clear ownership: a data platform team owns the pipeline, with a freshness SLA per use case, because real time costs much more than hourly batches and most analytics does not need it.
I would publish a few curated, denormalised models, like an orders fact table with region and product attributes, so analysts stop each writing their own 14-table join and get consistent numbers.
And I would budget compute per workload in the warehouse, with any remaining reporting on PostgreSQL under a constrained role with a statement timeout, so no report can take the product down.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, MySQL reference manual
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Analysts and product services both run complex multi-join queries on the same OLTP...": https://scrivio-interview-library.netlify.app/databases/query-optimization/f8cbb2df30/