06. Data Warehouse & Dimensional Modeling
Transactional databases are built to process one order at a time. A Data Warehouse is built to scan 500 million orders in 2 seconds to tell the CEO which product made the highest profit across 40 countries.
• Corporate Headquarters (OLAP / DWH): Gathers copies of daily receipts from 5,000 stores, consolidates them into unified clean tables, and answers strategic business questions.
OLTP vs. OLAP: The Two Halves of Data Engineering
Every database engine in the world is optimized either for high-speed row-level transactions (OLTP) or high-throughput columnar analytical aggregations (OLAP).
| Feature / Characteristic | OLTP (Operational Database) | OLAP (Analytical Warehouse) |
|---|---|---|
| Primary Purpose | Run real-time day-to-day business transactions (E-commerce cart, banking transfers). | Analyze historical business performance, calculate quarterly trends, executive BI. |
| Query Nature | Simple reads/writes of single rows: SELECT * WHERE user_id = 9201. |
Massive multi-table joins & aggregations: SUM(revenue), AVG(margin). |
| Database Engines | PostgreSQL, MySQL, Oracle, SQL Server, MongoDB. | Snowflake, Google BigQuery, Amazon Redshift, Databricks SQL, ClickHouse. |
| Storage Layout | Row-Oriented (writes fast whole tuples). | Column-Oriented (scans millions of values in 1 column). |
Dimensional Modeling: Fact Tables & Dimension Tables
In 1996, Ralph Kimball introduced the universal language of Business Intelligence: splitting tables into numerical Facts and descriptive Dimensions.
Fact Table (What happened?)
Contains numerical measurements of a business event. Usually narrow (mostly Foreign Keys and numbers) but contains billions of rows.
amount_usd, quantity_sold, discount_pct, duration_seconds.
Dimension Table (Who, Where, When?)
Contains rich textual context used to slice, dice, filter, and group the Facts. Usually wide (dozens of columns) but contains fewer rows.
dim_customer (city, state), dim_product (brand, category), dim_date.
Star Schema vs. Snowflake Schema
How dimension tables are arranged around the central Fact table.
Star Schema (Denormalized)
Dimensions connect directly to the central Fact table with 1 single join. Dimensions are intentionally denormalized (flattened), making SQL queries simple, lightning-fast, and easy for business analysts to understand.
Snowflake Schema (Normalized)
Dimensions are split into sub-dimensions (e.g. dim_product → dim_brand → dim_category). Reduces data redundancy, but requires complex multi-level SQL joins that can slow down analytical dashboards.
Slowly Changing Dimensions (SCD Type 1 vs. Type 2)
What happens when customer Alice moves from California to New York? How does your warehouse preserve sales history?
Simply updates Alice's state column to 'NY'.
Closes Alice's California record (end_date = '2026-10-10', is_current = FALSE) and inserts a new row for New York!
Interactive Star Schema Relationship Explorer
Click any Dimension table or the central Fact table to see how Foreign Keys connect the analytical model!