Star Schema & Snowflake Schema Design for Analytics
Design fact and dimension tables in star or snowflake layouts for BI.
In plain words
Keep the numbers in one big table, and the descriptions in smaller tables around it, joined by ids.
Think of it like…
A sales ledger (the fact table) where each line just records amounts and reference numbers, plus separate directories for customers, products and dates that explain what each reference number means.
Where you’ve seen it
An e-commerce warehouse: fact_order_lines (date_key, customer_key, product_key, quantity, revenue) joined to dim_date, dim_customer and dim_product. "Revenue by category and month" is two joins and a GROUP BY.
Words you’ll hear
- Fact table
- Measurable events at a declared grain, with numeric measures and foreign keys to dimensions.
- Dimension table
- Descriptive attributes for filtering and grouping (customer city, product category).
- Grain
- Exactly what one fact row represents, such as one product line on one order.
- Surrogate key
- A warehouse-generated id for dimension rows, which also supports keeping history (SCD).
Visual diagram
Theory & example queries
Facts, dimensions and grain
Design starts by declaring the grain: "one row per product per order". Every measure in the fact table must be true at that grain. Additive measures (revenue, quantity) can be summed across any dimension; semi-additive ones (account balance) can't be summed over time; ratios should be stored as their numerator and denominator.
Dimensions hold the descriptive attributes people filter and group by. A dedicated date dimension (with day of week, holiday flags and fiscal periods) makes calendar logic easy. Dimensions usually have surrogate keys, which also let you keep history when attributes change (slowly changing dimensions).
SELECT d.year_month, p.category, SUM(f.revenue)FROM fact_order_lines f JOIN dim_date d ON d.date_key = f.date_key JOIN dim_product p ON p.product_key = f.product_keyGROUP BY 1, 2;PostgreSQL is the lesson baseline unless noted otherwise.
Calculate the selected expressions and return the requested output columns.
Monthly revenue by category3 sample rows
| year_month | category | revenue |
|---|---|---|
| 2026-10 | Electronics | 425000 |
| 2026-10 | Home | 318500 |
| 2026-11 | Electronics | 467250 |
Note: Representative joined fact and dimension rows; revenue grouping and label format depend on the warehouse data.
Key takeaway: Declare the grain first; facts hold measures, dimensions hold descriptions.
Star or snowflake?
A star keeps each dimension denormalised: dim_product contains the category and department names directly. That repeats some text, but every query needs only one join per dimension, which BI tools and analysts handle easily.
A snowflake moves category and department into their own tables, which reduces duplication and makes some updates simpler, but adds joins to every query that uses them. Modern columnar warehouses (BigQuery, Snowflake, Redshift) compress repeated values well, so the storage savings matter less, and most teams default to stars, snowflaking only very large or shared hierarchies.
dim_product (product_key, name, category_key), dim_category (category_key, name, department_key), dim_department (department_key, name): "revenue by department" now needs three joins instead of one.
How it works, step by step
Follow one practical SQL workflow from start to finish. Select any step or play through the flow.
Pick the business process
Choose one process to model, such as orders, shipments or page views. Each gets its own fact table.
process = order lines
When to use it & trade-offs
What it is
A star schema organises analytics data into a central fact table of measurable events (one row per order line, with amounts and quantities) surrounded by dimension tables that describe them (date, customer, product, store). A snowflake schema normalises those dimensions further, for example splitting product into product → category → department.
Why it matters: Star schemas are the standard model for data warehouses and BI tools because they make reporting queries simple and fast: one join from the fact to each dimension. Data engineering and analytics interviews regularly ask you to design one, starting with declaring the fact table's grain.
When to reach for it
- Designing a data warehouse or analytics mart
- Feeding BI tools such as Power BI, Looker or Metabase
- Data engineering design interviews
When to avoid or be careful
- Mixing grains in one fact table (order totals and order lines together)
- Putting descriptive text in fact tables
- Snowflaking every dimension by default
Star vs snowflake vs one big table
Strengths: Simple queries, one join per dimension, BI-tool friendly.
Watch out: Repeated attribute values in dimensions.
Strengths: Less duplication; hierarchies managed in one place.
Watch out: More joins and more complex queries.
Strengths: No joins at all for consumers.
Watch out: Hard to maintain, and history and attribute changes get messy.
Interview signals & numbers to know
When this topic comes up
- “Design a data warehouse for …”
- “Fact vs dimension tables”
- “Star vs snowflake schema”
- “What's the grain?”
- BI reporting model
Benchmarks & rules of thumb
- 1
- grain per fact table
- 1 join
- per dimension in a star
- 3 types
- of measures: additive, semi-additive, non-additive
Common mistakes & follow-ups
Common interview mistakes
- Not declaring the grain, then summing order-level shipping fees on order-line rows.
- Storing a ratio such as conversion rate in the fact table, so it gets summed or averaged incorrectly.
- Joining facts to dimensions on natural keys whose values change over time.
Likely interviewer follow-ups
- How would you design a star schema for a food-delivery app's orders?
- What are slowly changing dimensions, and how would you store a customer moving city?
- When would you choose a snowflake over a star?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Star Schema & Snowflake Schema Design for Analytics with hands-on SQL practice and interview Q&A.