Overview
Curated: · Written: · Reviewed:
ETL for Reporting
In one line
Reporting ETL shapes governed warehouse tables into facts, dimensions, snapshots and aggregates at a declared grain, so a dashboard number is reproducible, point-in-time correct and safe to rerun. Reach for it when a BI tool needs stable, conformed serving tables rather than raw ingestion.
Key definitions
- Grain: what one row represents. State it before writing any transform.
- Surrogate key: a warehouse-controlled key on a dimension, so a business key can be re-keyed upstream without breaking history.
- Type 2 dimension: effective-dated versions with
valid_from,valid_toandis_current, joined point-in-time. - Idempotent load: rerunning the same interval converges to the same target state, by partition replace or merge on a stable key.
- Watermark: a completeness assumption, not proof that no older row will arrive.
- Last-known-good publish: build and validate a new version, then swap it in atomically.
Formulas and complexity
A join's output row count is the sum of per-key products, so a fan-out multiplies rows silently:
Distinct counts do not roll up by addition:
Two days of 1,000 uniques give a two-day count between 1,000 and 2,000, never 2,000 unless the audiences are disjoint.
How it works
The source is deduplicated to the target grain in staging, then joined at that grain. The job builds a new partition or version, not the live one. Quality gates run at input, transform and output. A pass swaps the new version in atomically. A fail blocks publication and leaves the last-known-good version live.
When to use and when not to
| Situation | Choose | Avoid |
|---|---|---|
| Trend or cohort needs attributes as they were at sale time | Type 2 dimension, point-in-time join | Type 1 overwrite, or joining history to today's attribute |
| Source corrects records up to 72 hours after the event | Reprocessing window at least 72 hours wide, merge on stable key | Watermark on max event time alone |
| Data must be filtered or masked before it lands | ETL, transform before load | ELT default when the constraint is upstream of the warehouse |
| High-cardinality ID needed only for drill-through | Degenerate dimension on the fact | A dimension table that adds joins for no analysis |
| Ratios, distinct counts, balances | Recompute from base facts | Summing pre-aggregated values |
Traps interviewers probe
- Fan-out from a join at the wrong grain. An order with three lines carries its revenue three times. Fix: aggregate the child table to the parent grain before joining, and enforce uniqueness at the declared grain with a test.
- Historical facts joined to the current dimension. Revenue by segment is reclassified whenever a customer moves. Fix: join on
fact_date BETWEEN valid_from AND valid_to, with non-overlapping intervals. - Summing daily uniques into a monthly figure. Fix: recompute the distinct count from base facts.
- Watermark-only incremental. A watermark never sees a correction to an old row. Fix: reprocess an overlap window at least as wide as the correction horizon, and merge on a stable key.
- Treating a successful task as correct data. An empty source publishes zeros and the scheduler reports green. Fix: check row count against the source manifest and reconcile to the source. Never turn a failed or partial load into zeros.
Interview tips
Open with the grain and the key: "Before the transform, I'd state the grain of this table and the key it must be unique on." Then say how history is handled, Type 1 or Type 2 and why.
Follow-ups to expect: backfilling six months without double-counting (partition replace, same code as the scheduled run); versioning a metric definition change; rolling back a bad publish (last-known-good); handling a late correction (overlap window and recorded load interval).
30-second outline: grain and keys first. History strategy second, with the reporting question that decides it. Idempotent load by partition or stable-key merge. Incremental with an overlap window sized to the correction horizon. Gates that block, then atomic publish. Reconcile aggregates to base facts.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.