Data Engineering interview question · Most asked
What is the grain of a table, and what is join fan-out?
Summary
The grain is what one row represents (one order, one order line, one daily total). Fan-out happens when you join a coarser table to a finer one: the coarse rows repeat for every match, so summing a coarse measure double-counts.
Longer Answer
Example: order totals joined to order lines repeats each order's total per line. Prevent it by declaring and testing every table's grain, joining facts to dimensions many-to-one, and computing measures at their own grain or allocating them down with an agreed rule.
Code Example
-- wrong: order-level total repeated per line
SELECT SUM(t.total) FROM order_totals t JOIN order_items i ON i.order_id = t.order_id;
-- right: sum at the line grain
SELECT SUM(i.quantity * i.unit_price) FROM order_items i;
Key Points
- Grain = what one row means.
- Coarse-to-fine joins repeat rows.
- Summing repeated measures double-counts.
- Test grains and reconcile totals.
Explanation
What interviewers look for
A concrete fan-out example and prevention techniques.
More most-asked Data Engineering questions
- Batch or streaming: how do you decide?
- What is the difference between ETL and ELT, and when would you choose each?
- What is change data capture (CDC), and why is log-based CDC preferred over polling?
- What does it mean for a data pipeline to be idempotent, and how do you achieve it?
- How do you implement incremental extraction, and what can go wrong?
- How do you deduplicate events, and what does 'exactly-once' really mean?
- What is a star schema, and why is it used in data warehouses?
- Explain slowly changing dimensions, especially Type 1 and Type 2.