Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. How to decide grain

Data modeling · Advanced Modeling

How to decide grain

Mediummodel-24
grainfact designatomicbusiness process

Question

How do you decide the grain of a fact table?

Solution

Start from the business process and the questions you must answer, then write one sentence: "One row per ___."

Decision checklist

1. What business process is this? (ordering, shipping, billing) 2. What is the most atomic event we need? (header vs line) 3. Which measures must be additive at that level? 4. Which dimensions attach naturally at that level? 5. Will anyone need lower detail later? Prefer atomic; aggregate in rollups

Process: e-commerce checkout
Questions: revenue by product, by day, by customer
Atomic grain: one row per order line
  (header-only grain cannot answer product questions)

Separate process: end-of-day inventory
Grain: one row per product per warehouse per day

Anti-patterns

  • Mixing headers and lines in one fact
  • Choosing a coarse grain that blocks future product analytics
  • Choosing ultra-fine click grain inside a revenue mart without need

Protect it

Document the sentence, add a uniqueness test on the grain key, and refuse to "just add a couple header rows."

Interview tip

Say the grain sentence before listing columns. Interviewers treat that as seniority signal.

PreviousNext