OLTP vs OLAP: databases, warehouses, lakes and lakehouses
Understand why app databases and analytics systems are built differently, why columnar storage is fast for analysis, and when to choose a warehouse, a data lake or a lakehouse. Includes the bronze-silver-gold layout.
Where you store data decides what you can do with it cheaply. A database that is perfect for taking orders can be terrible for analysing a year of them, and the other way round. This lesson explains why, and then walks through the four storage styles you will meet in every data job: databases, warehouses, data lakes and lakehouses.
A kitchen analogy helps. The billing counter is built for speed on one customer at a time: scan an item, take the money, next. The store room at the back holds everything in bulk in whatever shape it arrived. The accounts office is built to answer questions about thousands of bills at once. Different jobs, different layouts.
OLTP and OLAP
OLTP (online transaction processing) is what applications do all day: many small reads and writes touching a few rows each. "Create this order." "Mark order 42 as ready." "Fetch Asha's profile." The data must always be correct, so OLTP databases focus on transactions, constraints and fast lookups by key. Examples: PostgreSQL, MySQL, SQL Server, Oracle.
OLAP (online analytical processing) is what analysts and dashboards do: few queries, but each reads millions of rows and aggregates them. "Revenue by category by month for the last two years." Examples of OLAP systems: BigQuery, Snowflake, Amazon Redshift, ClickHouse, and Databricks SQL.
OLTP vs OLAP
| Property | OLTP database | OLAP warehouse |
|---|---|---|
| Typical work | Many small reads and writes | Few big scans and aggregations |
| Rows touched per query | A handful | Millions or billions |
| Data model | Normalised | Star schema or wide tables (see *Data modelling*) |
| Storage layout | Row by row | Column by column |
| Freshness | Always current | Loaded in batches or streams, minutes to hours old |
| Users | The application | Analysts, dashboards, data scientists |
| Example | PostgreSQL behind the Brew & Bean app | BigQuery holding Brew & Bean's history |
Why column storage makes analytics fast
A table is a grid. A row store keeps the grid row by row on disk: all fields of order 1, then all fields of order 2, and so on. That is ideal for "get everything about order 42" because the whole row sits together.
A column store keeps each column together: all the total values, then all the customer values. If you ask "what is the sum of total?" on a table with 30 columns, a column store reads only the one column it needs, around 1/30 of the data. Values in a column are also similar to each other, so they compress well. This is the main reason warehouses scan big tables quickly. Warehouses also spread the work over many machines in parallel.
The same table, two layouts
| order_id | customer | total | status |
|---|---|---|---|
| 1 | Asha | 300 | picked_up |
| 2 | Ravi | 120 | picked_up |
| 3 | Asha | 180 | cancelled |
Row store (on disk): [1, Asha, 300, picked_up] [2, Ravi, 120, picked_up] [3, Asha, 180, cancelled]
Column store (on disk): order_id: [1, 2, 3] customer: [Asha, Ravi, Asha] total: [300, 120, 180] status: [picked_up, picked_up, cancelled]SUM(total) in a column store reads only the total list.
Keep analytics off the app database
Do not run heavy analytics directly on the production OLTP database. A big report can slow down the very queries that customers' orders depend on. The usual fix is to copy data into a separate analytical store, which is exactly what data engineers' pipelines do.
Data warehouses
A data warehouse is a database built for analytics. It stores clean, structured, modelled data (often star schemas), speaks SQL, and is fast for aggregations. You load data into it with pipelines; you read from it with BI tools and SQL.
Modern cloud warehouses such as BigQuery and Snowflake separate storage from compute: data sits in cheap storage and you start or stop compute separately. This lets you pay for query power only when you use it, and lets several teams query the same data without slowing each other. Details and pricing models differ, and they change, so check each provider's documentation (we compare them in *Cloud data platforms*).
Warehouse trade-offs
- Strengths: very fast SQL on structured data, strong consistency, easy for analysts, good access control.
- Weaknesses: you must model and load data before using it; not ideal for raw files, images or text; cost grows with data scanned or compute used.
Data lakes
A data lake is a large store of files in cheap object storage (Amazon S3, Google Cloud Storage, Azure Data Lake Storage). You can dump anything into it: CSV, JSON, logs, images, PDFs, database exports. You decide the structure when you read the data (called *schema on read*), not when you write it.
The lake's strength is flexibility and low cost. Its danger is the data swamp: files nobody understands, with no schema, no owner, duplicated and half-updated. Without management, finding trustworthy data becomes harder than collecting it.
Lake trade-offs
- Strengths: cheap, holds any format, good for raw copies, ML and unstructured data.
- Weaknesses: no built-in transactions, easy to end up with inconsistent or unreadable data, slower and harder for analysts to query directly.
Lakehouses
A lakehouse tries to give you the best of both. Data stays as open files in cheap lake storage, but a table format adds the things a warehouse has: a schema, ACID transactions (changes are all-or-nothing), the ability to update and delete rows, and time travel (query the table as it was yesterday). Delta Lake, Apache Iceberg and Apache Hudi are the best-known open table formats. Platforms such as Databricks, and the major warehouses, now support lakehouse-style tables. The next module has a lesson, *File and table formats: Parquet, Delta Lake and Iceberg*, that explains how they work.
The idea is one copy of the data that SQL analysts, Spark jobs and ML engineers can all use.
Warehouse vs lake vs lakehouse
| Question | Warehouse | Lake | Lakehouse |
|---|---|---|---|
| Data types | Structured | Anything | Mostly structured plus files |
| Schema | On write | On read | Enforced by the table format |
| Transactions | Yes | No (just files) | Yes, through the table format |
| Cost of storage | Higher | Lowest | Low (lake storage) |
| Ease for analysts | Easiest | Hardest | Good with a SQL engine on top |
| Typical use | BI and reporting | Raw landing zone, ML data | One platform for BI and ML |
A common layered design: bronze, silver, gold
Many teams organise a lake or lakehouse in three layers, often called the medallion pattern.
Medallion layers
| Layer | Contents | Who uses it |
|---|---|---|
| Bronze (raw) | Data exactly as it arrived, never edited | Data engineers, for reprocessing and audit |
| Silver (clean) | Cleaned, de-duplicated, typed, joined | Data engineers, data scientists |
| Gold (serving) | Business-ready tables such as daily_sales and star schemas | Analysts, dashboards, ML features |
For Brew & Bean: bronze holds the raw order exports and payment files as received, silver holds validated order lines with correct types, gold holds daily_sales and the star schema from the previous lesson.
Choosing: a practical guide
Rules of thumb
- A small business with structured data and SQL-skilled analysts: start with one cloud warehouse (or even PostgreSQL). Do not build a lake you do not need.
- Lots of raw files, logs, images or text, plus machine learning: a lake or lakehouse.
- Both BI and ML on the same large data: a lakehouse, or a warehouse plus a lake.
- Need results in seconds on huge, constantly arriving event data: look at specialised OLAP engines such as ClickHouse or Apache Druid.
- Data size under a few GB: a single PostgreSQL database is often enough. Bigger tools add cost and complexity.
Interviewers like to hear "it depends" followed by the questions you would ask: how much data, what shape, who queries it, how fresh must it be, what is the budget and the team's skills?
How this comes up in interviews
Common questions
- "What is the difference between OLTP and OLAP?"
- "Why are columnar formats faster for analytics?"
- "Warehouse vs data lake vs lakehouse: when would you use each?"
- "Why not run reports on the production database?"
- "What is a data swamp and how do you avoid it?" (Ownership, catalogue, schemas, a table format, naming and layers.)
You are a senior data architect. Recommend a storage design (database, warehouse, lake or lakehouse) for this situation, and explain the trade-offs. Ask me up to 3 questions first if needed.
Business: [e.g. an online store in India]
Data sources and volume: [e.g. orders table 20,000 rows/day, clickstream 5 million events/day, product images]
Who uses the data and how: [e.g. 5 analysts on dashboards, 2 data scientists]
Freshness needed: [e.g. hourly]
Team skills and budget: [e.g. strong SQL, small budget]
Give a layered design (raw, clean, serving) and say what you would NOT build yet.What to expect: A good answer is proportionate to the size, names a concrete layering, and explicitly says what to postpone. Be suspicious of any answer that recommends every tool.
Try it: Classify these workloads
For each workload say OLTP or OLAP and name a suitable store: (a) the app saving a new order, (b) the owner's weekly sales dashboard, (c) storing 2 TB of raw JSON logs for later analysis, (d) training a model on three years of customer behaviour.
Try it: Bronze, silver, gold for UPI
A payments app receives daily CSV settlement files from a bank with some bad rows. Describe what you would store in bronze, silver and gold, and one check at each step.
Key takeaways
- OLTP serves applications with many small reads and writes; OLAP serves analysis with few large scans.
- Column storage reads only the columns a query needs and compresses well, which is why warehouses are fast at aggregation.
- Warehouses hold structured, modelled data; lakes hold any files cheaply; lakehouses add table-format features (transactions, schema, time travel) on top of lake files.
- Bronze, silver and gold layers keep raw data safe and serve clean tables.
- Do not run heavy analytics on the production database; copy data to an analytical store.
- Pick the simplest option that fits your data size, users and budget.
Check yourself
Finishing the quiz marks the lesson as done.
1. Which workload is OLTP?
2. Why does a column store usually answer SUM(total) over a huge, wide table faster than a row store?
3. What does a lakehouse table format such as Delta Lake or Iceberg add on top of plain files in a lake?
4. A team dumps files into a lake with no owner, schema or documentation. Nobody can tell which files are current. What is this called?
5. A startup has 5 GB of structured order data and two analysts who know SQL. What is the most sensible starting point?
Saved on this device. Create a free account to keep it on every device.
Practise this with Sam
A real mock interview, out loud, with an honest scorecard. Free to start.