Scrivio Interview library
DesignPrincipal6 min read · updated 12 November 2026

Analytics workloads moved from OLTP databases to warehouses, then to lakehouses with SQL engines on object storage. As the senior technical leader, what does that history tell you about where window-heavy analytical SQL should run in your company, and how do you avoid fragmented logic across systems?

The history shows that analytics keeps separating from OLTP because the two workloads want different storage and resources: row stores and short transactions for services, columnar formats and big scans for analysis. Window-heavy historical SQL should run in the warehouse or lakehouse, fed by CDC, while near-real-time operational aggregates stay close to the service; the SQL skill itself is durable because windows and grouping are portable across engines. To avoid fragmented logic, I would define each metric once in a semantic layer and prefer platforms built on open formats such as Parquet and Iceberg.

Background to this question

Every company that has been around for a while carries layers of this history: reports still running on a replica of the order database, a warehouse that finance trusts, and a newer lakehouse where data scientists work in notebooks. The same metric, say monthly active customers, is often computed in all three, with three different answers. A senior leader is asked this question because the decision is less about which product to buy and more about where each kind of work belongs and how to keep one definition of the truth. In this answer, we will read the lesson of the history, look at what makes analytical SQL portable, place each workload, tackle the fragmentation problem, and choose platforms that keep options open.

1What the History Tells Us

In the beginning, reports ran against the operational database, because that is where the data was. That worked until a month-end report scanning 200 million rows slowed down checkout. Teams then moved analysis to read replicas, which protected the primary but still used a row store, a storage layout that keeps each row's columns together and is ideal for 'fetch order 123' but wasteful for 'sum one column over a billion rows'.

Data warehouses solved that with columnar storage: each column stored separately and compressed, so a query reading 3 of 40 columns reads a fraction of the data, and with massively parallel execution. Lakehouses then put the same columnar idea on cheap object storage, using open file formats such as Parquet and table formats such as Apache Iceberg, with several SQL engines able to read the same tables.

The lesson is that the separation persists for structural reasons. Transactions want small, indexed, row-at-a-time access with strict latency; analytics wants large, sequential, column-at-a-time scans with high throughput. Each generation of platform changed where analytics runs, but none put the two back together for large data.

Step throughWhere analytical SQL has run over time
  1. OLTP databaserow store; reports compete with transactions
  2. Read replicaprotects the primary; still a row store
  3. Data warehousecolumnar, parallel, fed by batch ETL
  4. Lakehousecolumnar open formats on object storage, many engines

4 layers, from the top down. Step through them one at a time.

Each step moved analysis further from the transactional store because the workloads want different storage.

2Why Window and Grouping SQL Is Durable

The good news for teams is that the analytical SQL itself has been remarkably stable. Window functions such as ROW_NUMBER, LAG and SUM OVER, CTEs and GROUP BY with ROLLUP are part of the SQL standard and work, with small dialect differences, on PostgreSQL, MySQL 8, the major cloud warehouses and the common lakehouse engines such as Trino and Spark SQL.

SQL
-- Monthly revenue with month-over-month change: runs with minor changes on most engines
WITH monthly AS (
SELECT date_trunc('month', created_at) AS month, SUM(total) AS revenue
FROM orders
GROUP BY 1
)
SELECT month, revenue,
revenue - LAG(revenue) OVER (ORDER BY month) AS change
FROM monthly;
-- 2025-05 | 1,200,000 | 80,000
-- 2025-06 | 1,150,000 | -50,000

So an engineer who learns windows and grouping well keeps that skill through every platform migration. That also tells us where to invest in training: SQL fluency pays off across platforms, while deep knowledge of one vendor's proprietary features ties us to it.

3Placing Each Workload

I would decide placement by freshness and scope. Operational aggregates that a service needs to make a decision now, such as 'orders by this customer in the last hour' for a fraud rule or 'stock reserved for this product', stay close to the service, in its own database or in a stream processor's state. They must be fresh within seconds and they involve one customer or product at a time.

Historical and cross-domain analysis, such as cohort retention over two years, revenue by region and channel, or anything joining data from several services, belongs in the warehouse or lakehouse. It is fed by change data capture, CDC, which reads each service database's change log (for example with Debezium into Kafka) and lands the changes in analytical tables with a lag of minutes, without querying the services' databases at all.

The anti-pattern is a heavy window query, written for a dashboard, running against a service's primary database. It works on day one and becomes an incident on the day the table is ten times larger.

4Avoiding Fragmented Metric Logic

Fragmentation is the bigger risk than platform choice. When 'active customer' is defined in a Java service (logged in within 30 days), in a dashboard (placed an order within 30 days) and in a notebook (either, excluding staff), the company argues about numbers instead of acting on them.

The remedy is to define each business metric once, in one governed place, and have every consumer use that definition. A semantic layer, a model that sits between the tables and the tools and defines metrics, dimensions and joins, does this; dbt models with metric definitions, or the semantic models built into BI tools, are common choices. The definitions live in version control, have owners, have tests, and are reviewed like code. Dashboards and notebooks query the metric by name rather than re-deriving it.

Services that need a metric operationally either call an API backed by the same definition or, if they must compute it locally for latency, carry a test that compares their result with the warehouse's on a sample, so drift is caught.

Step throughOne metric definition, many consumers
  1. Service databasessource of truth for transactions
  2. CDC into the lakehouseminutes of lag, no load on services
  3. Semantic layer defines 'active customer'versioned, owned, tested
  4. Dashboards, notebooks, finance reportsquery the metric by name
  5. Does a service need it in real time?
    YesStream processor or local aggregate, tested against the definitionNoRead it from the analytical side

5 steps in order. Play them, or step through them one at a time.

5Choosing Platforms That Keep Options Open

Given that the platform has changed every five to ten years, I would evaluate new platforms on how easy it would be to leave them. Storing analytical data in open formats, Parquet files organised as Iceberg (or Delta Lake) tables, means several engines can read the same data, and a future migration changes the engine rather than copying petabytes. Standard SQL and a semantic layer that is not tied to one BI tool reduce lock-in further.

That does not mean avoiding managed warehouses; their operational simplicity is worth a lot. It means asking, before signing, how we would export the data and the metric definitions, and preferring vendors that read and write open table formats.

6Follow-up questions

Should near-real-time dashboards query the OLTP database?

Only for small, indexed queries on recent data. For anything heavier, I would use a stream processor that maintains the aggregate, or a real-time analytical store fed by Kafka, with the dashboard reading from there. The OLTP database's job is to serve transactions predictably.

How do you get teams to adopt the semantic layer instead of writing their own SQL?

Make it the easiest path: well-documented metrics, fast queries, and integration with the tools teams already use. Then retire duplicates actively by showing where numbers disagree and fixing them together. Executive reporting that only uses governed metrics creates a strong pull.

What about cost control on the lakehouse?

Window-heavy queries over full history are expensive on pay-per-scan engines. Partitioning tables by date, clustering by common filters, and materialising frequently used aggregates as incremental tables keep scan volumes down, and per-team cost reporting makes the trade-offs visible.

7Conclusion

In this answer, we saw that analytics keeps separating from OLTP because row stores and columnar stores serve different workloads, while window and grouping SQL has stayed portable across every generation of platform. Historical, window-heavy analysis belongs in the warehouse or lakehouse fed by CDC, near-real-time operational aggregates stay close to the service, each metric is defined once in a semantic layer to avoid fragmented logic, and open formats such as Parquet and Iceberg reduce lock-in for the next migration.

What to say in the interviewAbout 80 seconds aloud

Open with

The history tells me two things. First, analytics keeps moving away from OLTP for structural reasons: transactions want row stores, indexes and short predictable queries, while analytics wants columnar storage and big parallel scans.

Then, if they want more

Warehouses and then lakehouses on object storage were each a better home for that second workload, but none of them merged the two back together. Second, the SQL itself is durable: window functions, CTEs and grouping are standard and portable across PostgreSQL, warehouses and lakehouse engines, so SQL skills survive every platform change.

So I'd put window-heavy historical and cross-domain analysis in the warehouse or lakehouse, fed by CDC from the service databases, and keep near-real-time operational aggregates, the ones a service needs to decide something now, close to the service or in a stream processor.

The biggest risk is fragmentation, the same metric defined differently in a service, a dashboard and a notebook. I'd fix that with a semantic layer where each metric is defined once, versioned, owned and tested, and consumers query it by name.

And I'd evaluate platforms on open formats like Parquet and Iceberg, so the next migration changes the engine rather than the data.

About this answer

Last updated
12 November 2026
Versions it names
MySQL 8
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.
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 "Analytics workloads moved from OLTP databases to warehouses, then to lakehouses with SQL...": https://scrivio-interview-library.netlify.app/databases/advanced-sql/8c0d5b9e50/