Topic 213 / Advanced
Data lake and data warehouse (OLTP vs OLAP)
Chapter 13.5 · Data Lake and Data Warehouse
What and why
An OLTP database (→ 69, → 70) is built for many small transactions touching whole rows; asking it to scan millions of rows for an aggregate — "total revenue by region last quarter" — is the wrong workload for row-oriented storage, which must read every column of a row even when the query needs only two. A data warehouse flips both the storage orientation (columnar) and the workload shape (large scans, few writes) to make that analytical query fast; a data lake is the lower-cost, less-structured landing zone — often built on object storage (→ 79) — that raw data lands in before or alongside the warehouse. Builds on: → 123 (batch processing and ETL — the pipelines that feed both).
Diagram
| OLTP | OLAP (warehouse) | |
|---|---|---|
| Workload | Many small reads/writes | Few large scans/aggregates |
| Storage orientation | Row-oriented | Column-oriented |
| Example query | "This order's status" | "Revenue by region, last quarter" |
| Consistency need | Strong, transactional | Eventually complete is fine |
Source OLTP ──CDC (→119)──► Lake: raw zone → cleaned zone → curated zone ──► Warehouse queries
How it works
- OLTP stores data row-oriented because a transaction touches whole rows; OLAP stores data column-oriented because an analytical query touches whole columns across many rows — reading 2 of 50 columns then costs only those 2 columns' worth of bytes, not full rows.
- A star schema models data as fact tables (events: sales, clicks) referencing small, reused dimension tables (product, customer, time), denormalized (the opposite choice from → 63) for query simplicity rather than write efficiency.
- ELT pipelines (→ 123's pattern, load before transform instead of transform before load): extract from source systems, load the raw data into the lake first, then transform inside the warehouse or lake engine — preserving raw data so a bad transform can be redone from the untouched source.
- Lake zones: raw (unmodified ingested data) → cleaned (deduplicated, typed, validated) → curated (aggregated, modeled for specific consumers) — each zone is a checkpoint, so a bad transform corrupts only the zone it ran in, not the raw data behind it.
- Table formats (Parquet/Iceberg-style, named as examples) add a metadata layer — schema evolution, atomic writes, time travel — on top of plain columnar files sitting in object storage (→ 79); this metadata layer is what turns a folder of files into a lakehouse with warehouse-like guarantees.
- Feeding from CDC (→ 119): rather than a nightly export of the OLTP database, CDC streams every row change into the lake's raw zone continuously, narrowing the gap between operational data and what the warehouse can answer about it.
Practical example
(illustrative). An order database answers "this order's status" by
primary key in a few milliseconds; asked to sum revenue by category across a year, it
would scan and lock production tables. Instead, CDC streams order changes into the lake's
raw zone; a transform builds a fact table of orders joined to a product dimension; the
analytical query reads only the revenue and category columns of that columnar fact
table — a fraction of the bytes a row-store equivalent would touch — without ever reaching
the production OLTP tables.
When to use it
- Use when: analytical queries over large row counts or long time ranges are frequent enough to need dedicated infrastructure, or raw data must be retained for multiple downstream uses a single OLTP schema can't serve.
- Avoid when: analytical needs are occasional and small enough that a read replica or a few summary tables already answer them.
- Failure scenarios: analytical queries run directly against production OLTP, degrading transactional latency; a lake's raw zone becoming an unowned dumping ground with no schema, pushing cleanup downstream indefinitely; a CDC pipeline falling behind so the warehouse looks fresh but is actually stale by hours.
- Simpler alternative: a read replica of the OLTP database, or a handful of materialized views, for moderate analytical needs.
Practice
(Process kind — design exercise; 20–30 min, shared lab: Postgres). Using the Postgres lab, design a star schema — one fact table, two dimension tables — for a small order dataset, as DDL or on paper. Write one query against a normalized schema and the equivalent query against your star schema, and state which direction query complexity moved versus write complexity. Done when you can state which workload (OLTP or OLAP) your star schema is now worse at.
Shared lab setupKey takeaway
OLTP and OLAP serve different workloads by design — row-oriented transactions versus column-oriented scans — and a lake/warehouse exists to serve the second without touching the first. Done when you can: design a star schema and name which workload it trades away. Used next in → 214 (the streaming counterpart to this batch warehouse); Project 19.
References
None — this topic makes no external claims.
Source directory