OLTP vs OLAP: Row Stores, Column Stores and Data Warehouses
At 09:00 on Monday, someone in finance opens a dashboard: revenue by region by week for the last two years. The dashboard runs one SQL query against the production Postgres primary. The orders table has 1.2 billion rows.
The query reads about 240 GB from disk. It pushes the hot working set for checkout out of the buffer cache, so checkout queries that took 3 ms now take 80 ms. It holds a snapshot open for 25 minutes, so vacuum cannot clean up dead rows on the busiest tables. The checkout p99 alert fires. Someone kills the query, and finance asks why “a simple report” takes down the site.
Nothing is wrong with Postgres. It is a transaction-processing engine being asked to do analytics, and the two workloads want opposite storage layouts. This article explains why, and where analytics should run instead.
What OLTP and OLAP are
OLTP (online transaction processing) is the application workload: many small reads and writes, each touching a few rows by key. “Get order 8812”, “insert this payment”, “decrement stock”. Latency in milliseconds, thousands to millions of operations per second, strict correctness. Postgres, MySQL, DynamoDB and the databases you have met so far are OLTP systems.
OLAP (online analytical processing) is the analysis workload: few queries, each scanning millions or billions of rows but only a handful of columns, aggregating them into a small result. “Sum revenue by region by week.” Seconds are fine; throughput in bytes scanned per second is what matters.
| OLTP | OLAP | |
|---|---|---|
| Typical query | Point lookup or small range by key | Scan, filter, group, aggregate |
| Rows touched | 1 to 100 | Millions to billions |
| Columns touched | Most of the row | 3 to 10 of maybe 100 |
| Writes | Constant small transactions | Bulk loads or micro-batches |
| Storage layout | Row-oriented | Column-oriented |
| Bottleneck | Latency, locks, IOPS | Bytes scanned, CPU per row |
How it works
Row vs column storage, byte by byte
Take an orders table with 20 columns and about 200 bytes per row. A row store such as Postgres puts each row’s fields next to each other in an 8 KB page, as described in storage engines:
Row store, one 8 KB page holds about 40 rows:
[id=1|cust=77|region=EU|amount=19.99|status=paid|created=...|...17 more fields]
[id=2|cust=12|region=US|amount=5.00 |status=paid|created=...|...17 more fields]
[id=3|cust=77|region=EU|amount=42.10|status=refd|created=...|...17 more fields]
To sum amount, the engine must read every page, which means every byte of every row, to extract 8 bytes out of 200. That is 4% useful data.
A column store writes each column separately, in large blocks:
Column store, each column in its own file or segment:
id: 1, 2, 3, 4, 5, ...
region: EU, US, EU, EU, APAC, ...
amount: 19.99, 5.00, 42.10, 7.50, 11.00, ...
created: 2026-11-01, 2026-11-01, 2026-11-01, ...
Now SUM(amount) GROUP BY region reads only the amount and region columns. The other 18 columns are never touched. Point lookups get worse (fetching one whole order means reading 20 separate places), and single-row updates are expensive, which is why column stores batch writes. That trade is the whole story.
Compression: columns compress far better
A column holds values of one type, often sorted or repetitive, so it compresses extremely well:
- Dictionary encoding:
regionhas 6 distinct values. Store a 1-byte code per row instead of a string. - Run-length encoding: if data is sorted by
region, “EU repeated 400 million times” is a single entry. - Delta and frame-of-reference encoding: timestamps and IDs that increase slowly store as small differences.
- Bit-packing: a
statuswith 4 values fits in 2 bits.
Column stores commonly reach 5x to 10x compression on typical business data, versus maybe 2x to 3x for compressed row pages, because neighbouring values are similar. Less data on disk means less data to read.
Vectorized execution and pruning
Row engines process one row at a time through the query plan, paying function-call overhead per row. Column engines process batches of a few thousand values from one column at once in tight loops the CPU can run with SIMD instructions, often operating directly on compressed data. This is why ClickHouse or DuckDB can aggregate hundreds of millions of rows per second per core.
They also skip data they do not need. Every block stores min and max values per column (zone maps, or Parquet row-group statistics). A filter created >= 2026-11-01 skips every block whose max created is older. Sorting or clustering data by the most common filter column makes this pruning dramatic.
Star schemas
Analytical models are usually dimensional: a large fact table of events (one row per order line, with numeric measures and foreign keys) surrounded by small dimension tables that describe them. This is the star schema, and it is deliberately denormalised for scanning, the opposite trade from OLTP modelling covered in data modeling and denormalization.
erDiagram
FACT_ORDER_LINES }o--|| DIM_DATE : "date_key"
FACT_ORDER_LINES }o--|| DIM_CUSTOMER : "customer_key"
FACT_ORDER_LINES }o--|| DIM_PRODUCT : "product_key"
FACT_ORDER_LINES }o--|| DIM_REGION : "region_key"
FACT_ORDER_LINES {
bigint date_key
bigint customer_key
bigint product_key
bigint region_key
int quantity
decimal revenue
}
DIM_DATE {
bigint date_key
date day
int iso_week
string quarter
}
DIM_PRODUCT {
bigint product_key
string category
string brand
}
A dashboard query scans billions of narrow fact rows, joins to small dimensions (which fit in memory), and groups by dimension attributes. Column stores and star schemas fit each other perfectly.
Where the data comes from: ETL, ELT and CDC
Analytics needs a copy of OLTP data in an analytical store. There are two broad pipelines:
- ETL (extract, transform, load): transform in a separate engine, load the finished tables. Historically used because warehouses were expensive.
- ELT (extract, load, transform): load raw data into the warehouse first, then transform with SQL inside it, usually managed with dbt. Now the default, since warehouse compute is elastic and keeping raw data lets you rebuild models.
The extract step should not be nightly SELECT * against the primary. Use change data capture (CDC): read the database’s replication log (Postgres logical decoding, MySQL binlog) with a tool like Debezium, publish changes to Kafka, and apply them to the warehouse or lakehouse every few seconds or minutes. This puts almost no load on the primary and keeps analytics minutes behind, not a day. The mechanics and the outbox pattern are in outbox, inbox and CDC, and continuous transformations are in stream processing. Managed variants exist too, such as Aurora zero-ETL integrations into Redshift.
flowchart LR APP["App"] --> PG["Postgres primary<br/>OLTP"] PG -->|"logical decoding"| DBZ["Debezium"] DBZ --> K["Kafka topics"] K --> LH["Lakehouse tables<br/>Iceberg on S3"] LH --> WH["Warehouse or engine<br/>Snowflake, BigQuery,<br/>Trino, ClickHouse"] WH --> BI["Dashboards and ML"] style PG fill:#EEEDFE,stroke:#534AB7,color:#3C3489 style K fill:#F1EFE8,stroke:#888780,color:#444441 style LH fill:#E1F5EE,stroke:#0F6E56,color:#085041 style WH fill:#E1F5EE,stroke:#0F6E56,color:#085041
Where it breaks
Running analytics on the primary. Long scans evict hot pages from the buffer cache, saturate disk I/O, and hold old snapshots open so MVCC cleanup (vacuum in Postgres, purge in InnoDB) falls behind and tables bloat. Never point BI tools at the primary.
Running analytics on an OLTP replica. Better, but long queries on a Postgres replica trigger recovery-conflict cancels, or with hot_standby_feedback they bloat the primary, as explained in read replicas in practice. It is a stopgap for modest reports, not an analytics platform.
Treating a column store as OLTP. Single-row updates and deletes are expensive in column stores: they rewrite or mark whole blocks. ClickHouse, for example, is built for append-heavy data and handles updates through background merges and specialised table engines. Use the warehouse for reads at scale and keep transactional truth in the OLTP database.
Small files in the lake. Streaming CDC into object storage every few seconds creates millions of tiny Parquet files, and query planning and reading slow to a crawl. Table formats need regular compaction and snapshot expiry.
Freshness vs cost. Real-time analytics is possible but costs more compute and more complexity. Agree on a freshness target per dataset (5 minutes, 1 hour, daily) instead of “real time everywhere”.
Semantic drift. “Revenue” defined differently in three dashboards is the most common analytics failure, and no storage engine fixes it. Keep metric definitions in one modelled layer.
Real-world systems
Cloud warehouses separate storage from compute and scale both elastically:
- Snowflake stores data in its own columnar format on object storage and runs queries on independently sized virtual warehouses, so ETL and dashboards do not fight for CPU. It can also manage and query Apache Iceberg tables.
- Google BigQuery is serverless: no clusters to size, with on-demand pricing by bytes scanned or reserved capacity, on top of the Dremel execution engine and the Capacitor columnar format.
- Amazon Redshift runs MPP clusters (RA3 nodes with managed storage) or Redshift Serverless.
Lakehouses keep data as open files (usually Parquet) in object storage and add an open table format on top, which gives ACID commits, snapshots and time travel, schema evolution and partition evolution, so many engines can safely read and write the same tables:
- Apache Iceberg has the broadest engine support (Spark, Trino, Flink, Snowflake, BigQuery, Redshift, Athena, DuckDB and more) and has become the common choice for open tables. Its v3 spec, ratified in 2025, adds deletion vectors, row lineage and a variant type. Amazon S3 Tables (since December 2024) are S3 buckets that store Iceberg tables natively and handle compaction for you.
- Delta Lake is the format behind Databricks; its UniForm feature writes Iceberg metadata alongside so Iceberg readers can use the same tables.
- Apache Hudi focuses on upsert-heavy, incremental pipelines.
Embedded and real-time engines: ClickHouse is an open source column store built for sub-second queries over billions of rows, common for observability, product analytics and user-facing dashboards. DuckDB is an in-process column engine (think SQLite for analytics) that queries Parquet and Iceberg files directly from a laptop or a server process.
HTAP (hybrid transactional and analytical) systems keep a row store and a column store of the same data inside one product. TiDB adds TiFlash columnar replicas that receive data as Raft learners, so analytical queries see fresh data without touching the row nodes. SingleStore combines rowstore and columnstore tables. Google AlloyDB for PostgreSQL has a columnar engine that keeps hot columns in memory. SQL Server has columnstore indexes on OLTP tables. HTAP removes the pipeline for moderate analytics on fresh data, but heavy analytics and data from many sources still belong in a warehouse or lakehouse.
How to apply it
| Situation | Reasonable default |
|---|---|
| Startup, one Postgres, a few reports | Run them on a dedicated replica or DuckDB over nightly exports; plan CDC early |
| Several sources, BI team, under a few TB | Managed warehouse (Snowflake, BigQuery or Redshift) with ELT via dbt |
| Many engines, ML on the same data, large volumes | Lakehouse on Iceberg, with a warehouse or Trino for SQL |
| Sub-second analytics in a product (user-facing dashboards, logs) | ClickHouse or a similar real-time column store fed from Kafka |
| Fresh analytics on transactional data inside one system | An HTAP database, if its OLTP side also fits |
Checklist:
- Keep analytical queries off the primary by policy, enforced with separate credentials.
- Extract with CDC from the replication log, not periodic full scans.
- Model facts and dimensions; cluster or partition fact tables by the main filter column, usually date.
- Choose freshness per dataset and size compute for it.
- Compact small files and expire old snapshots in lake tables.
- Define each business metric once.
Interview questions
Q1: Why are column stores faster for analytics, and slower for OLTP?
Analytical queries touch a few columns across many rows, so storing each column contiguously means reading only those columns; similar adjacent values compress 5x to 10x; zone maps skip blocks that cannot match the filter; and vectorized operators process thousands of values per CPU loop. Together that cuts bytes read and CPU per row by orders of magnitude. OLTP is the reverse: fetching or updating one whole row means touching every column file, and in-place updates break compression, so column stores batch writes and handle updates with merges or delete markers, which makes single-row transactions slow.
Q2: Finance wants live revenue dashboards. The team proposes pointing the BI tool at a read replica. What do you say?
It works for light, short reports, but it does not scale. Long scans on a Postgres replica either get cancelled by recovery conflicts or, with hot_standby_feedback, hold back vacuum on the primary and bloat production tables. A physical replica also cannot have analytics-specific indexes or a different schema, and it is still a row store reading 200 bytes per row to use 17. Instead, stream changes with CDC into a column store or Iceberg tables, model a revenue fact table clustered by date, and serve the dashboard from there with a freshness target such as 5 minutes. If the volume is small and freshness must be near zero, an HTAP database with columnar replicas is another option.
Q3: What does an open table format like Iceberg add on top of Parquet files in S3?
Parquet gives an efficient columnar file. A table format adds a metadata layer that tracks which files make up each version of the table, so writers commit atomically (readers see the old snapshot or the new one, never half a write), you can time-travel to old snapshots, evolve schema and partitioning without rewriting data, and let multiple engines read and write the same table safely through a catalog. Without it, a directory of Parquet files has no transactions, no consistent view during writes, and query engines must list directories to find data, which is slow on object storage.
✅ Key takeaways
- OLTP serves many small keyed transactions with row storage; OLAP scans few columns over huge row counts with column storage. Opposite layouts for opposite workloads.
- Column stores win by reading only needed columns, compressing 5x to 10x, skipping blocks with zone maps and executing in vectorized batches. Together that is often a 100x to 1,000x reduction in bytes read.
- Never run analytics on the primary, and treat OLTP replicas as a stopgap. Feed analytics with CDC from the replication log.
- Warehouses (Snowflake, BigQuery, Redshift) separate storage and compute; lakehouses put open table formats, with Apache Iceberg the most widely supported, on object storage.
- ClickHouse and DuckDB cover real-time and embedded analytics; HTAP systems like TiDB with TiFlash serve fresh analytics inside one database.
🧠 Check your understanding
0 / 4-
1A table has 50 columns. A query sums one column over all 2 billion rows. Why does a column store read so much less data than a row store?
A row store must read whole pages, so every column comes along. A column store reads one column file, and similar values next to each other compress well. Indexes are the OLTP tool for finding few rows, which is why that option is tempting but wrong for full aggregations.
-
2What is the main difference between ETL and ELT?
The order of load and transform is the difference. ELT became the default because warehouse compute is elastic and keeping raw data lets you rebuild models. Both still transform data, and both can be batch or incremental.
-
3Your nightly job runs SELECT * over the orders table on the primary to copy it to the warehouse. What is the better design?
CDC reads changes the database already writes to its log, so it adds almost no query load and keeps the warehouse minutes behind instead of a day. More frequent full scans still hammer the primary, and indexes do not help a SELECT * of every row.
-
4What does an open table format like Apache Iceberg provide that plain Parquet files in a bucket do not?
Parquet already gives columnar compression. Iceberg adds a metadata layer that defines which files belong to each table snapshot, which enables ACID commits, time travel and schema or partition evolution across engines. It does not turn the lake into an OLTP store.
Where to go next
- Time-series databases: a specialised column store for metrics and events ordered by time.
- Outbox, inbox and CDC: how to get changes out of the OLTP database reliably.
- Stream processing: continuous transformations between Kafka and your analytical tables.
- Sharding and partitioning: why cross-shard reports belong here and not as scatter-gather on production.
Finished this lesson?
Mark it complete to track your progress across the roadmap.