Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 36/ 160
02. SQL & Data Engineering Basics

OLTP vs OLAP & Data Warehouses

Contrast transactional systems with analytical warehouses and columnar query engines.

IntermediateOLTP · OLAP3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

One kind of database runs the app, handling many small updates fast; the other is built to read huge amounts of data for reports and analysis.

Think of it like…

A shop's till and its accounts office. The till handles one customer at a time, quickly, all day (OLTP). The accounts office reads months of receipts at once to produce reports (OLAP). If the accountant took the till's receipts away mid-day to add them up, customers would queue.

Where you’ve seen it

A dashboard query summing a year of orders ran against the production PostgreSQL primary every morning at 9, slowing the app for 90 seconds. The data team replicated tables to a warehouse every 15 minutes with change data capture. The same aggregation over 400 million rows now takes 3 seconds in the columnar warehouse (reading only the date and amount columns) and the app is unaffected, at the cost of the dashboard being up to 15 minutes behind.

Words you’ll hear

Row store vs column store
Rows kept together (fast to read or write one record) vs columns kept together (fast to scan a few columns across many rows).
Data warehouse
A system optimised for analytical queries over integrated, historical data.
CDC (change data capture)
Streaming row changes from the OLTP log into the warehouse.
Read replica
A copy of the OLTP database for read traffic; helps, but is still row-oriented.

Visual diagram

Loading interactive diagram

Theory & deep dive

Two workloads, two designs

OLTP queries look like UPDATE accounts SET balance = balance - 500 WHERE id = 42 or SELECT * FROM orders WHERE id = 981. Row storage keeps a record's columns together, which makes reading or writing one whole row fast, and indexes find rows quickly. The system favours low latency, high concurrency and ACID guarantees, and schemas are normalised.

OLAP queries look like SELECT region, SUM(amount) FROM orders WHERE order_date >= '2026-01-01' GROUP BY region. Columnar storage keeps each column's values together, so the engine reads only the columns it needs, compresses them well (similar values are adjacent) and processes them in vectorised, parallel batches across many machines. Warehouses are optimised for large scans and aggregates, accept bulk loads rather than single-row updates, and use denormalised or star schemas.

Why columnar wins for analytics

An orders table has 30 columns, but a revenue query needs 2. A row store reads all 30 columns for every row; a column store reads just those 2 columns, about 15× less data before compression, so the scan is much faster and, in pay-per-scan warehouses, cheaper.

Key takeaway: Row stores serve transactions; column stores serve scans and aggregates.

Practical consequences for data scientists

Get data from the warehouse, or from a read replica if there's no warehouse, and keep exploration queries bounded (LIMIT, date filters, sampled tables). Accept the freshness lag and record it: a model trained on data "as of 09:00" should say so. Don't expect warehouse tables to have enforced foreign keys or uniqueness; check them yourself. Be careful with cost models: some warehouses bill by bytes scanned (BigQuery on-demand), others by compute time (Snowflake), so select needed columns and filter on partitions.

Lines are blurring: Postgres extensions and engines like DuckDB and ClickHouse bring analytics speed closer to applications, HTAP systems combine workloads, and lakehouse formats (Delta Lake, Iceberg, Hudi) put warehouse-style tables on object storage. For ML work, the practical pattern remains: operational data → pipeline → warehouse or lakehouse → feature tables → notebooks and training jobs, with scheduled, reproducible extracts.

Cost-aware querying

In BigQuery, SELECT * FROM events over a 5 TB table scans all columns and bills for 5 TB, while SELECT user_id, event_ts FROM events WHERE event_date = '2026-11-01' on a date-partitioned table scans a single day of two columns, often under a gigabyte.

Key takeaway: Query the warehouse, mind freshness and cost, and verify constraints yourself.

How it works, step by step

Step 1 of 4
Discover

1. Identify where the data lives

Find whether you have a warehouse, a replica or only the primary, and how fresh each copy is.

warehouse lag: 15 minutes
Key numbers at this step
Primary
off limits for scans

When to use it & trade-offs

What it is

OLTP (online transaction processing) databases such as PostgreSQL or MySQL run applications: thousands of small reads and writes per second, each touching a few rows, with strict consistency and row-oriented storage. OLAP (online analytical processing) systems, the data warehouses (Snowflake, BigQuery, Redshift, ClickHouse), answer questions that scan millions or billions of rows and aggregate a few columns, using columnar storage, compression and parallel execution. The data scientist's rule: analyse in the warehouse, not on the production database.

Why it matters: A heavy analytical query on the production primary can slow checkout for customers, and a warehouse is also where history, joined sources and clean models live. Understanding the two workloads explains why reports are built from a copy of the data, why the warehouse lags the app by minutes or hours, and why the same query can be instant in one system and impossible in the other.

When to reach for it

  • Dashboards and models built on warehouse tables
  • Moving heavy analysis off the production database
  • Explaining data freshness to stakeholders

When to avoid or be careful

  • Running large aggregates on the production primary
  • SELECT * on wide warehouse tables
  • Assuming warehouse tables enforce uniqueness

OLTP vs OLAP

OLTP (PostgreSQL, MySQL)
Best for: Running applications and transactions

Strengths: Low-latency writes; ACID; row lookups by key.

Watch out: Slow and risky for large analytical scans.

OLAP warehouse (Snowflake, BigQuery, Redshift)
Best for: Analytics, BI and feature building over history

Strengths: Columnar scans at scale; integrated sources.

Watch out: Not for single-row updates; data is slightly behind.

Read replica of OLTP
Best for: Light reporting when no warehouse exists

Strengths: Fresh; protects the primary.

Watch out: Still row-oriented; heavy scans remain slow.

Interview signals & numbers to know

When this topic comes up

  • “The app slows down when analysts run reports”
  • “Why is the warehouse data 15 minutes old?”
  • “OLTP vs OLAP?”
  • Columnar storage
  • Lakehouse

Benchmarks & rules of thumb

~15× -
less data read for 2 of 30 columns in a column store
3 s vs 90 s -
warehouse query time vs production impact in the example
15 min -
replication lag in the example

Common mistakes & follow-ups

Common interview mistakes

  • Running a full-table aggregate on the production primary at peak time.
  • Training a model on a warehouse snapshot without noting its as-of time.
  • Selecting all columns in a pay-per-scan warehouse.

Likely interviewer follow-ups

  • Why are warehouses columnar?
  • Why shouldn't analysts query the production database?
  • What is a lakehouse?
Interview tip: Explain with the till and accounts-office analogy, then give one cost or latency number. It keeps the answer concrete.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply OLTP vs OLAP & Data Warehouses with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Normalization vs Denormalization
Next topic
Star & Snowflake Schema Modeling