OLTP vs OLAP
Two fundamentally different database workload patterns. Transactions vs Analytics.
1The Store Analogy
OLAP (Accountant's Desk): End of month, analyze all sales. Which products sold best? What's the trend? Complex queries across millions of records.
OLTP (Online Transaction Processing): Optimized for many small read/write transactions. Think: placing orders, updating profiles.
OLAP (Online Analytical Processing): Optimized for complex analytical queries on large datasets. Think: business intelligence, reporting.
2Key Differences
| Aspect | OLTP | OLAP |
|---|---|---|
| Purpose | Day-to-day operations | Analysis & reporting |
| Queries | Simple, by primary key | Complex aggregations |
| Data | Current state | Historical data |
| Operations | INSERT, UPDATE, DELETE | SELECT (mostly) |
| Users | Many concurrent users | Few analysts |
| Response Time | Milliseconds | Seconds to minutes |
| Schema | Normalized (3NF) | Denormalized (star/snowflake) |
3OLTP Characteristics
High Concurrency
Thousands of users making small transactions simultaneously
ACID Compliance
Transactions must be atomic, consistent, isolated, durable
Normalized Schema
Minimize redundancy, optimize for writes
Row-Oriented Storage
Optimized for accessing entire rows
Examples: PostgreSQL, MySQL, Oracle, SQL Server for transactional workloads.
4OLAP Characteristics
Complex Queries
Aggregations, GROUP BY, window functions across billions of rows
Columnar Storage
Store data by column for efficient analytics scans
Denormalized Schema
Star/snowflake schema optimized for reads
Batch Updates
Data loaded periodically via ETL, not real-time
Examples: Snowflake, BigQuery, Redshift, ClickHouse, Apache Druid.
5Data Warehouse Architecture
Typical Flow
6Key Takeaways
?Quiz
1. A query needs to find total sales by region for the past year. Which system?
2. Which storage format is better for OLAP?