# Slowly Changing Dimensions

> Track how dimension attributes change over time with SCD Types 0, 1, 2 and others, and implement Type 2 history correctly. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/data-engineer/slowly-changing-dimensions
Last updated: 2026-11-28

Track how dimension attributes change over time with SCD Types 0, 1, 2 and others, and implement Type 2 history correctly.

Intermediate · about 6 hours · difficulty 4/5

Learn first: [Dimensional Modeling: Star and Snowflake Schemas](https://www.internhack.in/roadmaps/tracks/data-engineer/dimensional-modeling)

Customers move cities, products change price categories, sellers switch plans. If your dimension simply overwrites the value, last year's report suddenly shows this year's attributes. Slowly changing dimension (SCD) techniques fix that.

### The common types

- **Type 0**: never change (date of birth, original signup channel).
- **Type 1**: overwrite. No history. Fine for typo fixes.
- **Type 2**: add a new row for each change with `valid_from`, `valid_to` and an `is_current` flag. Full history; the fact joins to the version valid at event time.
- **Type 3**: keep a "previous value" column. Limited history.
- **Type 4 and 6**: history tables and hybrids; know the names, rarely needed.

### Implementing Type 2

1. Compare incoming records with current dimension rows on the natural key.
2. For changed rows, close the old version (`valid_to = change_time`, `is_current = false`).
3. Insert the new version with a new surrogate key.
4. Facts store the surrogate key of the version current when the event happened.

In SQL this is usually a `MERGE` statement. In dbt, **snapshots** implement it for you.

### Choosing per column

Decide type per attribute, not per table. A seller's GSTIN correction might be Type 1 while their city is Type 2.

### Pitfalls

- Overlapping or gapped validity ranges caused by timezone or boundary errors (use half-open ranges: `valid_from <= t < valid_to`).
- Joining facts to the current dimension row when you needed the historical one.
- Creating a new version on every load because of a meaningless change like a trailing space.

You are ready to move on when you can write a MERGE (or dbt snapshot) that maintains a Type 2 customer dimension and a query that reports orders by the customer's city at the time of each order.

## Key concepts

- **SCD Type 0 and Type 1**
- **SCD Type 2**
- **SCD Type 3**
- **Types 4 and 6**
- **valid_from, valid_to, is_current**
- **MERGE-based implementation**
- **Point-in-time joins**

## Mini project

Build a Type 2 customer dimension in PostgreSQL or DuckDB. Load three daily snapshots where some customers change city, run your MERGE each day, and verify there are no overlapping validity ranges.

## Check yourself

A customer moved from Pune to Bengaluru in June. How does a Type 1 vs Type 2 dimension change the answer to 'revenue from Pune customers in Q1'?

## Free resources

- [dbt snapshots](https://docs.getdbt.com/docs/build/snapshots) (dbt Labs)
- [Kimball dimensional modeling techniques](https://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimensional-modeling-techniques/) (Kimball Group)
- [Slowly changing dimension](https://en.wikipedia.org/wiki/Slowly_changing_dimension) (Wikipedia)

Previous: [Dimensional Modeling: Star and Snowflake Schemas](https://www.internhack.in/roadmaps/tracks/data-engineer/dimensional-modeling) · Next: [Modern Modeling Approaches](https://www.internhack.in/roadmaps/tracks/data-engineer/modern-modeling)

## More in Data Modeling

- [OLTP vs OLAP Workloads](https://www.internhack.in/roadmaps/tracks/data-engineer/oltp-vs-olap)
- [Normalization and Relational Design](https://www.internhack.in/roadmaps/tracks/data-engineer/normalization)
- [Dimensional Modeling: Star and Snowflake Schemas](https://www.internhack.in/roadmaps/tracks/data-engineer/dimensional-modeling)
- [Slowly Changing Dimensions](https://www.internhack.in/roadmaps/tracks/data-engineer/slowly-changing-dimensions)
- [Modern Modeling Approaches](https://www.internhack.in/roadmaps/tracks/data-engineer/modern-modeling)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Data Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/data-engineer)
