Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 48/ 160
03. Data Warehousing & Data Modeling

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.

AdvancedSCD2 · History · Types 0–63 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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_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.

Visual diagram

Loading interactive 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.

Slowly Changing Dimensions in one concrete design

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.

Key takeaway: SCD policies determine whether dimension attribute changes overwrite history, create versioned rows, keep prior/current fields, split into mini-dimensions, or combine selected techniques

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.

Key takeaway: 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.

How it works, step by step

Step 1 of 4
SCD2

1. 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.

ignore, overwrite, or preserve history
Key numbers at this step
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_to and 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

SCD2
Best for: Historical attribute handling rules: Type 0 retains original, 1 overwrites, 2 versions, 3 stores limited old/new, 4 history table, and 6 hybrid fields.

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.

History
Best for: A full versioned dimension policy that preserves prior values with effective dates and a current indicator.

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.

Types 0–6
Best for: The facts' source event time or business effective time used to resolve one valid dimension version.

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_to and 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_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.

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_to and 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?
Interview tip: Lead with the data path and failure boundary: SCD policies determine whether dimension attribute changes overwrite history, create versioned rows, keep prior/current fields, split into mini-dimensions, or combine selected techniques. Then make the answer operational: 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.

Knowledge check

Loading quiz

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.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
Star Schema vs Snowflake Schema vs Galaxy Schema
Next topic
Surrogate Keys vs Natural Keys & Hash Keys