Slowly changing dimensions
SCD Type 1 (overwrite), 2 (row versioning with valid_from/valid_to + current flag), 3 (previous-value column) — and how Type 2 answers "what did we know then?".
The mental model
A slowly changing dimension is version control for business entities. A customer's address, a product's price tier, a sales rep's territory — these change occasionally (slowly), and every change forces the same question a git repo answers for code: do you keep only the latest state, or the full history of states?
- **SCD Type 1** is
git commit --amend: overwrite in place, history destroyed. The dimension always shows current truth. - **SCD Type 2** is a real commit log: every change creates a **new row** (a new "commit") with validity timestamps —
valid_from,valid_to,is_current. Old facts keep pointing at the old version; you can check out any point in time. - SCD Type 3 is a single "previous value" column: one step of undo, nothing more.
Why this exists — what breaks without it: facts are recorded against dimension members *as they were at event time*. If a customer moves from Pune to Bengaluru in March and you overwrite the region (Type 1), every January order silently teleports to Bengaluru — last year's regional revenue report changes *retroactively*, dashboards disagree with their own screenshots, and finance's audited numbers drift. Type 2 exists to answer the question every serious analytics organization eventually needs: "what did we know at the time?" — sales credited to the territory that made them, risk scored with the model inputs that existed then, cohorts frozen at signup-time attributes.
The cost is honest: Type 2 multiplies rows, complicates joins (as-of range predicates instead of equality on a current key), and turns the load into a small state machine. The skill is choosing per attribute, not per table: correction-type changes (typo in a name) are Type 1 even inside a Type 2 dimension; history-bearing changes (territory, tier, pricing plan) are Type 2.
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision