OLTP vs OLAP & Columnar Storage
Why analytical queries need a different database, how column orientation changes everything, and the modern pipeline from operational data to insight.
#Two workloads, two systems
OLTP (Online Transaction Processing) — the operational database. Many small, fast operations touching few rows each, found by key.
SELECT * FROM orders WHERE id = 4711;
UPDATE inventory SET qty = qty - 1 WHERE sku = 'ABC';Thousands per second, single-digit milliseconds, strict correctness, current state only.
OLAP (Online Analytical Processing) — the analytics database. Few large queries, each scanning millions or billions of rows and aggregating.
SELECT region, DATE_TRUNC('month', created_at), SUM(total)
FROM orders WHERE created_at > '2024-01-01'
GROUP BY 1, 2;A handful per minute, seconds to minutes, read-only, full history.
These are so different that trying to serve both from one database serves neither well — the classic symptom being an analytics query that reads so much data it hogs the production database's disk and memory, so checkout queries queue behind it and time out. Separating them is the first thing to say when a design mixes reporting with transactions.
#Row vs column storage
The structural reason OLAP databases are so much faster at analytics.
ROW-ORIENTED (OLTP) — all fields of a row stored together
[1|Alice|Pune |4999][2|Bob|Delhi|1299][3|Cara|Pune|8800]
▲ fetching one whole row = one contiguous read ✓
▲ SUM(total) must read EVERY field of EVERY row ✗
COLUMN-ORIENTED (OLAP) — each column stored together
ids: [1][2][3]
names: [Alice][Bob][Cara]
cities: [Pune][Delhi][Pune]
totals: [4999][1299][8800] ◄── read ONLY this for SUM(total)The consequence: a query touching 3 of 50 columns reads ~6% of the data instead of 100%. On a terabyte table that's the difference between 20 seconds and 20 minutes.
Three more advantages compound it:
Compression is dramatically better. A column holds one kind of value, over and over — city might have 200 distinct values across a billion rows. That repetition is exactly what compression feeds on: store each city name once and refer to it by number (dictionary encoding), or record "Pune, 40,000 times" instead of writing it 40,000 times (run-length encoding). Columnar data routinely compresses 10:1 where row data manages about 2:1. Less data on disk means less I/O, and I/O is the bottleneck.
Vectorised execution. When a million values of the same type sit side by side, the CPU can apply one instruction to a batch of them at once instead of looping one at a time — often 10× faster per byte.
Late materialisation. Do the filtering against the compressed columns first, and only bother assembling complete rows for the handful that survive. For SELECT name, email FROM users WHERE city = 'Pune' AND age > 60, read just the city and age columns to find the matching row positions — say 2,000 out of 100 million — and only then fetch name and email for those 2,000.
The cost: writing or updating a single row means touching every column file. Columnar stores are therefore append-and-batch oriented — most don't support efficient single-row updates at all, which is exactly why they're unsuitable for OLTP.
#Making scans cheap
Beyond column orientation, analytical stores avoid reading data at all:
Partitioning. Split by a column, usually date. A query with WHERE created_at > '2024-06-01' skips entire partitions — partition pruning.
Zone maps / min-max indexes. Each block stores the min and max of each column. A query filtering total > 10000 skips any block whose max is below that. Cheap, automatic, and extremely effective when data is naturally clustered — when similar values already sit near each other, as timestamps do in a table that's only ever appended to.
Sort keys / clustering. Physically ordering data by a frequently-filtered column makes zone maps far more selective. If rows are stored in random order, every block holds a mix of small and large totals, so every block's min–max range overlaps the filter and nothing can be skipped. Sorted by total, each block covers a narrow range, and most blocks can be ruled out. This is often the single highest-impact tuning decision in a warehouse.
Materialized views / rollups. Pre-aggregate common queries. Turns a billion-row scan into a thousand-row lookup — and the pre-aggregation is where most of the "real-time analytics" magic lives.
Note the pattern: analytical databases barely use B-tree indexes. Their strategy is "scan fast and skip aggressively" rather than "seek precisely" — a genuinely different philosophy, and a good thing to articulate.
#The systems
| System | Type | Best at |
|---|---|---|
| Snowflake / BigQuery / Redshift | Cloud warehouse | Ad-hoc SQL over huge history, separated storage/compute |
| ClickHouse | Columnar OLAP | Very fast aggregations, real-time ingest, self-hosted |
| Apache Druid / Pinot | Real-time OLAP | Sub-second queries on streaming data, user-facing analytics |
| DuckDB | Embedded OLAP | Local/single-node analytics; surprisingly capable |
| Parquet + Spark/Trino | Lake / query engine | Cheap object storage, flexible compute |
Separation of storage and compute is the defining feature of the modern warehouse: data lives in object storage, compute clusters spin up on demand and scale independently. You pay for storage cheaply and for compute only when querying — and two teams' queries don't compete for the same machines.
#The pipeline
OLTP DBs ──┐
Event ├──► ingest ──► LAKE ──► transform ──► WAREHOUSE ──► BI
streams ──┤ (CDC, (raw, (dbt, (modelled, dashboards
3rd-party──┘ batch) Parquet) Spark) columnar) ML, ad-hocETL vs ELT. The old way transformed data before loading (ETL), because storage and compute were expensive. The modern way loads raw data first and transforms inside the warehouse (ELT), because storage is cheap and warehouse compute is powerful. ELT means you keep the raw data, so when a transformation turns out to be wrong you can reprocess rather than having lost the original — which is usually decisive.
Getting data in: CDC from operational databases (low latency, no application changes), event streams for behavioural data, and batch loads for third-party sources.
The medallion structure is the common organizing convention: bronze (raw, as-ingested), silver (cleaned, deduplicated, typed), gold (business-level aggregates the analysts actually query). Worth naming because it shows familiarity with how these systems are actually organized.
#Lakehouse
The lake gave cheap storage of anything but no transactions, no schema enforcement, and no efficient updates — the "data swamp" problem. Table formats (Iceberg, Delta Lake, Hudi) add a metadata layer over Parquet files in object storage that provides:
- ACID transactions over files, so concurrent writers don't corrupt each other.
- Schema evolution with enforcement — you can add or rename columns safely, and writes that don't match the table's schema are rejected instead of silently landing as junk.
- Time travel — query the table as of a past version.
- Efficient upserts and deletes (which also makes GDPR deletion — erasing one person's data on request — tractable in a lake).
- Partition evolution — change how the table is partitioned (say from monthly to daily) for new data without rewriting the files already written.
The result behaves like a warehouse (transactions, schemas, updates) but costs like a lake (plain files in cheap object storage), and many engines can query it rather than it being locked into one vendor. Iceberg has become the common denominator.
#Real-time analytics
When dashboards must reflect the last few seconds — user-facing metrics, live operational monitoring, an ad click dashboard — batch pipelines are too slow.
The lambda architecture ran a fast approximate streaming path alongside a slow exact batch path and merged them. It works, and it means maintaining the same business logic twice in two systems, which is where it usually breaks down.
The kappa architecture uses one streaming path and reprocesses from the retained log when logic changes. Simpler and now more common, enabled by log systems that retain long history.
In practice, real-time OLAP stores (Druid, Pinot, ClickHouse) collapse the distinction: they ingest from a stream, pre-aggregate on write (update running totals like "clicks per ad per minute" as each event arrives, rather than storing raw events and summing them at query time), and serve sub-second aggregate queries directly. For most "real-time dashboard" requirements this is the pragmatic answer.
#Check yourself
OLTP versus OLAP?Show answer
Why run analytics on a separate system?Show answer
Why is column storage so much faster for analytics?Show answer
Name two encodings that make columns compress well.Show answer
Why are column stores bad at OLTP?Show answer
How do analytical stores avoid reading data?Show answer
ETL versus ELT — why did ELT win?Show answer
Lambda versus kappa architecture?Show answer
#What to carry forward
- Separate OLTP from OLAP early; replicate via CDC and accept seconds of lag for reporting.
- Column storage reads only touched columns and compresses about 10:1 — the root of analytical speed.
- Analytical stores skip data (partitions, zone maps, sort keys) instead of seeking with B-trees.
- Separating storage from compute is the defining feature of the modern warehouse.
- ELT keeps raw data so mistakes can be reprocessed; organise it as bronze, silver and gold.