Dimensional Modeling: Star and Snowflake Schemas
Model analytical data with Kimball-style fact and dimension tables, choose the grain, and decide between star and snowflake schemas.
Intermediate · about 8 hours · difficulty 3/5
Learn first: Normalization and Relational Design
Dimensional modeling, popularised by Ralph Kimball, is still the most common way to structure warehouse data for analysis. Interviewers love asking you to design one.
Facts and dimensions
- Fact tables store measurable events at a declared grain: one row per order line, per payment, per app session. They hold numeric measures (amount, quantity) and foreign keys to dimensions.
- Dimension tables describe the who, what, where, when: customer, product, restaurant, date, city.
- Date dimension: one row per day with attributes like weekday, month, fiscal quarter (April to March in India) and festival flags such as Diwali sale days.
The four-step design process
- Pick the business process (orders, payments, deliveries).
- Declare the grain (one row per order item).
- Identify the dimensions.
- Identify the facts (measures).
Star vs snowflake
- Star schema: each dimension is one wide, denormalized table joined directly to the fact. Simpler and usually faster.
- Snowflake schema: dimensions are normalized into sub-tables (product, category, department). Less duplication, more joins.
Most modern teams prefer stars because storage is cheap and analysts want fewer joins.
Fact table types
- Transaction facts: one row per event.
- Periodic snapshot: one row per entity per period (account balance per day).
- Accumulating snapshot: one row per process instance updated as it moves (order placed, picked, shipped, delivered).
Also know additive, semi-additive (balances) and non-additive (ratios) measures.
Pitfalls
- Mixing grains in one fact table (order-level and item-level rows together).
- Summing semi-additive measures like balances across time.
You are ready to move on when you can design a star schema for a quick commerce company (Blinkit-style) with a clearly stated grain, three dimensions and the measures, and justify each choice.
Key concepts
- Fact and dimension tables
- Declaring the grain
- Date dimension
- Star schema
- Snowflake schema
- Transaction, periodic and accumulating facts
- Additive vs semi-additive measures
- Conformed dimensions and bus matrix
- Factless facts and junk dimensions
Mini project
Design and build a star schema in DuckDB or PostgreSQL for a sample e-commerce dataset: fct_order_items, dim_customer, dim_product, dim_date. Write five business queries against it and document the grain of every table.
Check yourself
A product belongs to a category which belongs to a department. Show how this looks in a star schema and in a snowflake schema, and argue for one.
Free resources
- Kimball dimensional modeling techniques (Kimball Group)
- dbt best practices (dbt Labs)
- Star schema (Wikipedia)