Data modelling · core
Grain, facts and the star schema
A warehouse model starts with the grain of the fact table: what one row means. Facts hold measures, dimensions hold descriptions, and a star schema with flat dimensions is the default.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- State the grain before anything else, for example one row per order item. Mixing two grains in one fact table causes double counting.
- Measures: additive (amounts, can be summed over everything), semi-additive (balances, summed across loans but never across days) and non-additive (ratios, computed and not stored).
- Fact kinds: transaction (one row per event, insert-only), periodic snapshot (one row per entity per period, such as a loan balance each day), accumulating snapshot (one row per process with a date for each milestone, updated as it moves), and factless (events with no measure, for counting and for what did not happen).
- Order id kept in the fact is a degenerate dimension. Conformed dimensions (date, city, customer) are shared by facts, so reports across facts agree.
- Order-level discount: allocate it to lines by share of value and put the rounding remainder on the largest line so the paise add up, or keep it only in an order-level fact.
- Star: one fact table with flat, denormalised dimensions, one join per dimension. Snowflake: dimensions split into normalised tables, more joins, and tiny space savings because columnar storage compresses repeated values.
- Use a snowflake only by exception, for example a large sub-dimension shared by several dimensions or owned by another team (an outrigger).
- Junk dimension: low-cardinality flags (cash on delivery, first order, app or web) in one small table. Role-playing dimension: one date dimension used as order date, ship date and delivery date through views or aliases.
- Physical design: surrogate keys to dimensions, partition by the order date in IST, cluster by city or restaurant.
The red pen
Common traps: mistake → fix
Mistake: Snowflake schema is better because normalisation is always better
Fix: in analytics the star is the default.
Mistake: The snowflake schema is the same as the Snowflake product
Fix: they are unrelated.
Mistake: Balances can be summed over days
Fix: semi-additive measures use the last value or an average over time.
Easy to hard
Questions interviewers ask, easy to hard
- What is the grain of a fact table and why do you state it first?
- Star or snowflake schema: which is your default and why?
- What is the difference between a transaction fact and a periodic snapshot?
- Which fact table kind would you use for a loan application process?
- Design the tables for a food-delivery app so analysts can see revenue by city, restaurant and hour.
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.