Slowly Changing Dimensions (SCD Type 0, 1, 2, 3, 4 & 6)
Preserve history (or overwrite) attribute changes with the SCD type that matches audit needs.
In plain words
Ignore, overwrite, or preserve history. Next, hashes on governed fields. Finally, event time to exactly one dimension version.
Think of it like…
Type 1 replaces a name on every old passport; Type 2 keeps a dated passport history; Type 3 keeps only a small 'old/new' field on the current card.
Where you’ve seen it
CASE WHEN customer_sk valid at order_ts yields fact_orders.customer_sk; dim_customer closes old [valid_from, valid_to) and inserts the next surrogate when region changes from Type 2 attributes.
Words you’ll hear
- SCD2
- Historical attribute handling rules: Type 0 retains original, 1 overwrites, 2 versions, 3 stores limited old/new, 4 history table, and 6 hybrid fields.
- History
- A full versioned dimension policy that preserves prior values with effective dates and a current indicator.
- Types 0–6
- The facts' source event time or business effective time used to resolve one valid dimension version.
- Operational boundary
- Updating a Type 1 customer segment rewrites history, while multiple Type 2 rows without deterministic
valid_from/valid_toand an as-of join can double-attach facts or point to no current member. Choose an SCD type per attribute, key versions with non-overlapping validity, join facts to the surrogate valid at the event timestamp or explicit as-of policy, and keep one clear current-row filter.
Visual diagram
Theory & deep dive
SCD2: the working mechanism
SCD policies determine whether dimension attribute changes overwrite history, create versioned rows, keep prior/current fields, split into mini-dimensions, or combine selected techniques.
Ignore, overwrite, or preserve history. Hashes on governed fields, then deterministic validity intervals; this exposes the state governed by Types 0–6.
CASE WHEN customer_sk valid at order_ts yields fact_orders.customer_sk; dim_customer closes old [valid_from, valid_to) and inserts the next surrogate when region changes from Type 2 attributes.
Slowly Changing Dimensions: failure mode and production response
Updating a Type 1 customer segment rewrites history, while multiple Type 2 rows without deterministic valid_from/valid_to and an as-of join can double-attach facts or point to no current member.
Choose an SCD type per attribute, key versions with non-overlapping validity, join facts to the surrogate valid at the event timestamp or explicit as-of policy, and keep one clear current-row filter. Track Validity overlap as "zero overlapping intervals per natural key at one instant", and make Current rows visible to the dataset owner.
How it works, step by step
Step 1 of 41. Classify attributes
Ignore, overwrite, or preserve history. SCD policies determine whether dimension attribute changes overwrite history, create versioned rows, keep prior/current fields, split into mini-dimensions, or combine selected techniques.
- Validity overlap
- zero overlapping intervals per natural key at one instant
- History
- A full versioned dimension policy that preserves prior values with effective dates and a current indicator.
When to use it & trade-offs
What it is
SCD policies determine whether dimension attribute changes overwrite history, create versioned rows, keep prior/current fields, split into mini-dimensions, or combine selected techniques. CASE WHEN customer_sk valid at order_ts yields fact_orders.customer_sk; dim_customer closes old [valid_from, valid_to) and inserts the next surrogate when region changes from Type 2 attributes.
Why it matters: Updating a Type 1 customer segment rewrites history, while multiple Type 2 rows without deterministic valid_from/valid_to and an as-of join can double-attach facts or point to no current member. Choose an SCD type per attribute, key versions with non-overlapping validity, join facts to the surrogate valid at the event timestamp or explicit as-of policy, and keep one clear current-row filter.
When to reach for it
- Preserve history (or overwrite) attribute changes with the SCD type that matches audit needs.
- Choose SCD2 because it provides this capability: Historical attribute handling rules: Type 0 retains original, 1 overwrites, 2 versions, 3 stores limited old/new, 4 history table, and 6 hybrid fields.
- Keep evidence for Validity overlap at "zero overlapping intervals per natural key at one instant" so the last production stage-Join as-of - event time to exactly one dimension version-remains testable.
When to avoid or be careful
- Updating a Type 1 customer segment rewrites history, while multiple Type 2 rows without deterministic
valid_from/valid_toand an as-of join can double-attach facts or point to no current member. - Do not conflate History with SCD2. The second concept contributes different behavior: A full versioned dimension policy that preserves prior values with effective dates and a current indicator.
- Release only after this guardrail is in place: Choose an SCD type per attribute, key versions with non-overlapping validity, join facts to the surrogate valid at the event timestamp or explicit as-of policy, and keep one clear current-row filter.
SCD2 / History / Types 0–6 - roles, limits, and operating cost
Strengths: Historical attribute handling rules: Type 0 retains original, 1 overwrites, 2 versions, 3 stores limited old/new, 4 history table, and 6 hybrid fields. SCD policies determine whether dimension attribute changes overwrite history, create versioned rows, keep prior/current fields, split into mini-dimensions, or combine selected techniques.
Watch out: Updating a Type 1 customer segment rewrites history, while multiple Type 2 rows without deterministic valid_from/valid_to and an as-of join can double-attach facts or point to no current member.
Strengths: A full versioned dimension policy that preserves prior values with effective dates and a current indicator. In this workflow it supports: Expire and insert - deterministic validity intervals.
Watch out: The operating cost is real: exactly one version with is_current=true.
Strengths: The facts' source event time or business effective time used to resolve one valid dimension version. Its output can be checked with Changed attributes.
Watch out: Operating guardrail: Choose an SCD type per attribute, key versions with non-overlapping validity, join facts to the surrogate valid at the event timestamp or explicit as-of policy, and keep one clear current-row filter.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for SCD2, and how would Validity overlap reveal it?”
- “Why is History distinct from this behavior: the facts' source event time or business effective time used to resolve one valid dimension version?”
- Production clue: Updating a Type 1 customer segment rewrites history, while multiple Type 2 rows without deterministic valid_from/valid_to and an as-of join can double-attach facts or point to no current member.
- Design probe: Choose an SCD type per attribute, key versions with non-overlapping validity, join facts to the surrogate valid at the event timestamp or explicit as-of policy, and keep one clear current-row filter.
Benchmarks & rules of thumb
- Validity overlap
- zero overlapping intervals per natural key at one instant
- Current rows
- exactly one version with `is_current=true`
- Changed attributes
- hash only fields whose history policy requires detection
Common mistakes & follow-ups
Common interview mistakes
- Updating a Type 1 customer segment rewrites history, while multiple Type 2 rows without deterministic
valid_from/valid_toand an as-of join can double-attach facts or point to no current member. - Reporting success from a job exit code without checking Validity overlap and Current rows.
- Treating this example as complete without replay, rollback, or access boundaries:
CASE WHEN customer_skvalid atorder_tsyieldsfact_orders.customer_sk;dim_customercloses old[valid_from, valid_to)and inserts the next surrogate when region changes from Type 2 attributes.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: Historical attribute handling rules: Type 0 retains original, 1 overwrites, 2 versions, 3 stores limited old/new, 4 history table, and 6 hybrid fields.
- What does the recovery plan do when this occurs? Updating a Type 1 customer segment rewrites history, while multiple Type 2 rows without deterministic
valid_from/valid_toand an as-of join can double-attach facts or point to no current member. - When is SCD2 insufficient for Current rows, and what does adding History cost in Validity overlap?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Slowly Changing Dimensions (SCD Type 0, 1, 2, 3, 4 & 6) with data engineer interview Q&A and hands-on practice.