Many small updates for live apps, or a few huge questions for analysts: two very different workloads.
OLTP and OLAP are two very different kinds of work for a database. Most systems end up needing both, in two separate places.
An OLTP database runs the business as it happens. A shopper clicks "Buy" and the system must find the cart, reduce the stock, write the order and take the payment, all in a few milliseconds, while thousands of other shoppers do the same. Every request touches only a handful of rows. What matters is low latency, high concurrency and correctness (ACID transactions).
An OLAP system answers questions about the business as a whole. "Which region grew fastest?" has to read one or two columns from every sale ever made. Such a query may run for seconds or minutes, and only a few analysts run them at once. What matters is scan speed and the ability to handle huge volumes.
Because the work is so different, the best design is different too. OLTP stores each row together, because the app wants the whole row, and uses indexes to jump to one row fast. OLAP stores each column together, because a report needs a few columns of all rows, and columns of similar values compress very well.
| OLTP | OLAP | |
|---|---|---|
| Purpose | Run the business | Understand the business |
| Typical query | Get or change one order | Total sales per region, per month |
| Rows touched per query | A few | Millions to billions |
| Queries per second | Thousands | A few at a time |
| Speed target | Milliseconds | Seconds to minutes |
| Storage layout | Row-oriented | Column-oriented |
| Schema | Normalized, many small tables | Denormalized: star or snowflake |
| Data freshness | Always the latest | Loaded in batches or near real time |
| Writes | Many small inserts and updates | Big bulk loads, few updates |
| Helped most by | Indexes, caching, ACID | Compression, scanning in parallel |
SELECT region, SUM(amount) FROM sales GROUP BY region
Lit squares are the data each store has to read. The picture is scaled down: 6 columns stand for all 40.
A simplified, illustrative model. Every value takes 8 bytes, columns compress 4 to 1, a disk scans 1 GB per second and each separate place costs 0.1 ms. Real databases add indexes, caches and many more tricks, so use this for the idea, not for numbers.
| Term | Meaning in easy words |
|---|---|
| OLTP | Online Transaction Processing: many small, fast reads and writes for a live app |
| OLAP | Online Analytical Processing: heavy queries that summarise lots of data |
| Row store | Stores all the values of one row together on disk. Good for fetching whole rows |
| Column store | Stores all the values of one column together. Good for scanning a few columns |
| Data warehouse | A database built for analysis, fed with data from other systems |
| Star schema | A big fact table surrounded by small dimension tables |
| Fact table | Records events or measurements, such as one row per sale |
| Dimension table | Describes the who, what, where and when of the facts |
| ETL | Extract, Transform, Load: copy data from sources into the warehouse in batches |
| CDC | Change data capture: stream every change from a database to other systems |
| HTAP | Hybrid transactional and analytical processing: one system serving both workloads |
| Choice | We gain | We lose |
|---|---|---|
| Separate OLAP system | Fast reports and a protected live app | Delay, cost and a pipeline to maintain |
| Reports on a read replica | Simple, no new system | Still row storage, so big scans are slow, and replica lag |
| Nightly batch (ETL) | Simple and cheap | Dashboards are up to a day old |
| Streaming (CDC) | Fresh data within seconds | More moving parts to run |
| Star schema (denormalized) | Simple, fast queries | Repeated data, and updates are harder |
| HTAP single system | One place, very fresh analytics | Complex engine, and often compromises on both sides |