OLTP vs OLAP
One table of four orders, stored two ways, shows why the database that records each sale is built differently from the one that adds them all up.
In 30 seconds
OLTP (online transaction processing) is the database behind the app: huge numbers of tiny reads and writes, each touching a row or two. It stores data row by row in tidy, normalised tables.
OLAP (online analytical processing) answers questions over everything: totals, trends, comparisons. Each query reads a few columns of millions of rows, so warehouses store data column by column, often in a star schema.
Because the two pull in opposite directions, companies usually run both and copy data from the first to the second.
OLTP vs OLAP, step by step
Simplified: real engines read disk pages holding many rows, and use indexes and caches. Some “HTAP” systems aim to serve both workloads from one database.
- Step 1: Two kinds of work. A shop’s data serves two jobs. Recording each sale as it happens is online transaction processing, OLTP. Asking questions about all the sales, such as revenue per month, is online analytical processing, OLAP.
- Step 2: OLTP: many small jobs. A transactional workload is a stream of tiny requests: add an order, update one, look one up. Each finds a row by its id, touches it and finishes in milliseconds, and many of them run at the same moment.
- Step 3: Row storage. OLTP databases store a table row by row: all the fields of order 101, then all of 102, and so on. Everything about one order sits together, so reading or changing a single order is one short trip to the disk.
- Step 4: OLAP: few huge reads. An analytical query asks about the whole table at once: total revenue is 3 + 8 + 5 + 9 = 25. It needs only one column, but from every row. Such queries are rare compared with transactions, yet each may read millions of rows.
- Step 5: Column storage. In a row store the four amounts are scattered, so the sum drags all 16 values past the reader. A column store keeps each column together: the sum reads 4 values and skips the rest. Neighbours of one type also compress well. The price: fetching one whole order now takes four separate reads.
- Step 6: Two schema shapes. OLTP tables are normalised: each fact is stored once, in many small linked tables, so a write changes one place. Warehouses usually prefer a star schema: one wide fact table of events with a few descriptive dimension tables around it, so a question needs only a few simple joins.
- Step 7: Two systems, one pipeline. The two workloads want opposite storage and schemas, and a long scan on the live database would compete with customers checking out. So the data is copied, in nightly batches or as a stream, into a separate warehouse, and analysts query the copy.
Try it yourself
Learn this first
Spotted a mistake on this page?