OLTP vs OLAP

Developed by S. Rathinagiri with Gemini

Real-world analogy

Suitcases vs wardrobes

Row storage packs each record together, like one suitcase per traveller. Column storage keeps like with like, like wardrobes for shirts, shoes and books. This is the usual pattern, not the definition: OLTP and OLAP differ by purpose, and some databases use both kinds of storage.

  1. Row store = suitcases. Each traveller's things are packed together, like one row with all its columns.
  2. OLTP: check in one traveller. Open one suitcase and you have everything. Fast.
  3. Count every shoe? With suitcases you must open all of them.
  4. Column store = wardrobes. The same things, sorted by type.
  5. OLAP: count every shoe. Open one wardrobe. That's why analytics uses columnstores.

OLTP vs OLAP: At a Glance

OLTP 🏃‍♀️

  • Purpose: Day-to-day operations
  • Data: Real-time, current
  • Queries: Simple, fast (Read/Write)
  • Database: Typically row-based storage

OLAP 🧠

  • Purpose: Analysis & decision making
  • Data: Historical, aggregated
  • Queries: Complex, multi-dimensional
  • Database: Typically columnar storage

OLTP: Normalized & ER Diagrams

Highly normalized to reduce redundancy, often visualized with ER diagrams where central entities are linked to attributes.

Primary Keys & Indexes

A primary key (like 'OrderID') uniquely identifies each row. Fast lookups come from indexing, and how rows are physically stored depends on the indexes and storage engine.

OLAP: Star Schema

Uses Star Schemas where a central fact table (like 'Sales') is surrounded by dimension tables.

Database Access Simulation

Click a button to start the simulation.

Disk (Row-Based)

Disk (Columnar)

OLTP: Entity-Relationship Diagram

Customers(PK) CustomerID...
Orders(PK) OrderID(FK) CustomerID...

OLAP: Star Schema

Sales Fact(FK)s...SalesAmount
DimCustomer(PK) CustomerID
DimProduct(PK) ProductID
DimDate(PK) DateID

From 2D Reports to a Sparse 3D Data Cube

Product Sales

Laptop (150)
Mouse (100)
Keyboard (80)

Monthly Sales

Jan (150)
Feb (80)
Mar (100)

Customer Sales

Cust A (100)
Cust B (150)
Cust C (80)
150
100
80
Product
Month
Customer

Multiple transactions are tracked across different reports.