OLAP vs OLTP
Two completely different jobs, two completely different database designs.
Key Points
- OLTP: optimized for fast, small, frequent reads and writes. Normalized schema. Think: your app's production database.
- OLAP: optimized for large, complex, read-heavy analytical queries across many rows. Denormalized schema. Think: your data warehouse.
- OLTP queries touch a few rows at a time. OLAP queries often scan millions.
- OLTP databases are row-oriented — the whole row is stored together. OLAP databases are often columnar — each column stored separately, making aggregations fast.
- Running heavy OLAP queries on an OLTP database is a bad idea — it slows down live operations and locks tables.
What it is
OLTP (Online Transaction Processing) systems handle the day-to-day operations of a business — individual inserts, updates, and deletes in real time. OLAP (Online Analytical Processing) systems are built for querying large volumes of historical data to support analysis and reporting. They're designed differently because they're used differently.
Why it exists
The workloads are fundamentally different in shape. A customer placing an order touches maybe 5 rows across 3 tables. A finance team asking 'what was our revenue by region last quarter?' might scan 50 million rows. The same database can't be optimally designed for both at the same time.
Intuition
When to use
- OLTP when you're building an application that reads and writes individual records in real time.
- OLAP when you're building reporting, dashboards, or analytical models over large historical datasets.
- Both when your system needs real-time operations and historical analysis — run them separately and sync data between them.
Common mistakes
- Running analytical queries directly on the production OLTP database. This is fine when the database is small. It becomes a serious problem as it grows.
- Assuming OLAP systems can handle real-time writes. Most are optimized for batch loads, not constant individual inserts.
Notes
- HTAP (Hybrid Transactional/Analytical Processing) is an emerging category that tries to do both at once. Systems like Google Spanner and TiDB sit here. For most organizations it's still cleaner to keep them separate.
- Columnar storage is the key technology behind modern OLAP speed. Aggregating over one column (e.g. sum of sales) only reads that column, not entire rows.
In practice
Every data warehouse you work in is an OLAP system. Understanding why it's separate from the production database explains why data can be a few hours stale, why the schema looks different from the application schema, and why batch loads exist.
Was this concept helpful?
Related concepts