Data platform · Storage & Modeling

Grain of a table

Mediumgrainmodelingfan-outmetrics

Interview question

What does table grain mean, and why does it matter?

How to answer

The short answer

Grain is the answer to: "What does 1 row represent?"

Examples:

  • 1 row per order
  • 1 row per order line
  • 1 row per customer per day
  • 1 row per page view event

If the grain is unclear, joins and aggregates silently double-count.

Output
fct_orders grain: 1 row per order
join to order_items (1 row per line) without care
  -> revenue duplicated across lines

How to protect grain

  • Document it in the model description
  • Enforce uniqueness tests on the grain key
  • Aggregate to the needed grain before joining facts

Interview tip: Start modeling answers with grain. Interviewers notice that habit.