All concepts

Slowly Changing Dimensions

A customer moves from London to Berlin. Should last year's orders now count as German? Your answer is the SCD type.

Pipelines & Orchestration · Intermediate · ~6 min

In plain English

A customer moves house. Do you correct every old invoice to the new address, or leave each invoice showing where they lived when it was sent?

Why it's worth your time

Choosing wrong silently restates published history — last quarter's numbers change and nobody knows why.

If you remember three things

  • Type 1 overwrites and restates history; Type 2 versions and preserves it
  • Facts must join on the version key captured at event time
  • Track only the attributes people slice by, or the dimension explodes

Overview

Dimension attributes change, and the warehouse has to decide what happens to history. Type 1 overwrites: the dimension always shows current truth, and every past fact is restated to match. Type 2 versions: the old row is closed with an end date, a new row opens, and each fact keeps pointing at the version that was current when it happened — so history stays as it was reported. Type 3 keeps a 'previous value' column for the one attribute where you want both. The reason this is a perennial interview question is that it exposes whether someone understands that a warehouse stores history, not state, and that the choice is a business decision rather than a technical one.

In an interview

SCD Type 1 overwrites the attribute, so all history is restated to current values. Type 2 closes the old row with an end date and inserts a new version with a fresh surrogate key, so facts stay joined to the value that was true at the time. Type 3 adds a previous-value column. Type 2 is the default for anything you report on, because restating history silently changes last quarter's numbers.

Production defaults

Default
Type 2 for anything reported on, Type 1 for contact details
Open end date
a far-future sentinel (9999-12-31), never NULL
Current flag
keep is_current for the common 'as it is now' query

What breaks

  • Type 2 dimension gives Type 1 answers — Facts are joining on the natural key. Resolve and store the surrogate key at fact-load time.
  • Dimension has millions of versions — You're tracking cosmetic attributes. Restrict Type 2 to reporting columns.

Watch it explained

Slowly Changing Dimensions For Data Engineers — Seattle Data Guy, 8:15

Related