The History Problem

A star schema holds 2 kinds of rows that age differently. A fact row records an event, and an event that has happened stays the way it happened. A dimension row describes a person, a product or a place, and those keep changing long after the event is over. Change tracking is the set of rules for what a dimension does when a source value changes.

A dimension that only knows today

Take a rental marketplace's warehouse. dim_host has one row per host. fact_booking has one row per booking and points at its host through host_key. Every night a load copies each host's latest values from the application database into the dimension.

On April 1, 2025 Marta earns the Superhost tier. The application updates her record, and that night's load writes Superhost over Standard in row 101. Nothing in fact_booking changes. Now run the first-quarter revenue report twice, once before that load and once after.

SELECT
    h.tier,
    SUM(b.amount) AS revenue
FROM fact_booking b
JOIN dim_host h
    ON b.host_key = h.host_key
WHERE b.booking_date < DATE '2025-04-01'
GROUP BY h.tier

The quarter was closed, no booking was added or edited, and the answer still moved. Marta's 2 first-quarter bookings, worth 800, now sit under a tier she did not hold when guests paid for them. The Standard line vanished because the join can only see the value stored today.

Why the join cannot recover the past

The fact row stores a pointer, host_key = 101, and the tier lives on the other side of that pointer. When the dimension row is overwritten, every fact pointing at row 101 picks up the new value at once, including bookings from years ago. The old value is gone from the warehouse, so no query can bring it back. A fact table is append-only, like the event logs you have modeled before. An overwritten dimension is the one mutable table in the star, and its edits reach backwards through every join.

Slowly changing dimensions

Attributes like tier, city, plan or sales territory change rarely and at unpredictable moments, while facts arrive constantly. Dimensional modeling calls a dimension with such attributes a slowly changing dimension, SCD for short. An SCD type is a rule for what the table does on a change: replace the value, add a row, or add a column. Those 3 rules are known as Type 1, Type 2 and Type 3.

Changes come in 2 kinds, and telling them apart shapes every later choice. A correction fixes a value that was never true, such as a misspelled name. A real-world change replaces a value that was true for a while, such as a host moving from Lisbon to Porto. After a correction, old facts should show the fixed value. After a real-world change, the right value for an old fact depends on the question being asked.

dim_host is overwritten nightly. A host with 12 bookings in May moves from Lisbon to Porto on June 20, and the load updates city. On July 1 an analyst reruns May's bookings-by-city report. What does it show for this host?

Before choosing a rule for any attribute, ask what a past fact should show after the value changes. The answer is sometimes the new value, sometimes the old one, and sometimes both. Each SCD type is built for one of those answers.

About this lesson

This section is part of the Change Tracking lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.