OLTP vs OLAP: why analytics databases are built so differently
If you have ever run a big report against your production database and watched the app slow down, you have bumped into the difference between OLTP and OLAP workloads.
OLTP: online transaction processing
This is the everyday work of an application: create an order, update a profile, look up one customer. Queries touch a small number of rows, need to be fast, and happen constantly. Traditional relational databases are designed for this, typically storing data row by row so a whole record can be read or written at once.
OLAP: online analytical processing
This is the question-asking side: total revenue by region per month, average session length across millions of users. Queries scan huge amounts of data but often only a few columns. Analytics systems usually store data column by column, which brings big advantages:
- Reading only the needed columns avoids loading everything else.
- Values in a column tend to be similar, so they compress very well.
- Operations like sums and averages can be processed in efficient batches.
Why not one database for both?
You can, up to a point. Small apps often run reports on a read replica and that is fine. But at larger scale, long analytical scans compete with short transactions for the same resources, and the storage layouts that make one fast make the other slower.
Common patterns
- Copy data from the operational database into a warehouse on a schedule (ETL or ELT).
- Stream changes continuously into an analytics store.
- Use hybrid systems that try to serve both, accepting some trade-offs.
Over to you:
- At what point did your team move reporting off the main database?
- Have you tried an embedded analytics engine for local analysis, and was it worth it?
Comments · 2
As a beginner: so you copy data into a separate database for reports, so heavy queries don't slow down the app? That finally makes sense.
This is where I see small teams make a mistake. A read replica gets you far before a full warehouse is worth the cost.