Skip to content
RED SAGSkills
mediumData Engineer interview question

How would you build a pipeline that maintains an SCD Type 2 customer dimension from a daily source extract?

What the interviewer wants to hear

  • Detect changes by comparing tracked attributes, often with a hash
  • Close the current row by setting valid_to and is_current false
  • Insert a new version with a new surrogate key and valid_from
  • Insert brand-new customers; decide how to handle deletes
  • Make it idempotent and use half-open date ranges
  • Test for one current row per key and no overlapping ranges

Model answer

I land the daily extract in staging, then compute a hash of the attributes I track, such as address and segment. I compare it with the current row in the dimension for each business key. Where the hash differs, a MERGE or two statements in one transaction close the old row by setting valid_to to the change time and is_current to false, then insert a new row with a new surrogate key, valid_from equal to the change time and valid_to set to a far-future date. Brand-new keys are inserted as current rows, and I agree with the business whether deletes close the row or set a deleted flag. I use half-open ranges so joins never match two versions, and I make the load rerunnable for the same date. Tests check exactly one current row per key and no overlapping ranges. In dbt, snapshots implement this pattern for me.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Data Engineer questions