IntermediateData Modeling · 17 min · 12 challenges

Change Tracking

Airbnb reviews Superhost status every quarter, so a host can hold the badge in spring and lose it by autumn. Suppose someone asks how much of last year's booking revenue came from Superhosts. If the host table only remembers today's badge, every past booking inherits it, and last year's answer shifts each time a review runs.

The History Problem

Daily Life
Interviews
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.

dim_host
host_keyhost_idhost_nametier
1014417Marta ReisStandard
1025230Jonas WeberSuperhost
fact_booking
booking_idhost_keybooking_dateamount
90011012025-02-14300
90021012025-03-20500
90031022025-03-22400
90041012025-04-10600

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 AS b
JOIN dim_host AS h
ON b.host_key = h.host_key
WHERE b.booking_date < DATE '2025-04-01'
GROUP BY h.tier
Run on March 31
tierrevenue
Standard800
Superhost400
Run on April 2
tierrevenue
Superhost1200
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.

What an overwrite destroys
  • ▸The value that was true when each past event happened.
  • ▸The date of the change, so before and after cannot be told apart.
  • ▸Repeatability: the same query over the same closed period returns a different answer next week.

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.
Multiple Choice

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.

Type 1: Overwrite Old Value

Daily Life
Interviews
Type 1 is the rule from the previous section, applied on purpose. When a source value changes, the load updates the dimension row in place and discards the old value. The table keeps one row per entity, the surrogate key stays the same, and no fact row is touched.
UPDATE dim_host
SET host_name = 'Aiko Tanaka'
WHERE host_id = 6102
Before the update
host_keyhost_idhost_namecity
1036102Aiko TankaOsaka
After the update
host_keyhost_idhost_namecity
1036102Aiko TanakaOsaka
Read one row of a Type 1 dimension as: this host, as the business knows them right now. That meaning covers every column in the row. A report that joins to it describes all of history using today's values, a style called as-is reporting.

Where overwriting is the right answer

Type 1 fits when
  • The old value was never trueCorrectionsA typo, a wrong birth year, a city entered by mistake. Old facts should show the fixed value, and restating past reports is the goal.
  • No report groups or filters by itContact and display fieldsEmail, phone number, profile photo. These are read for their current value and never used to slice revenue.
  • The business wants history under today's labelsAs-is questionsA product team asks how the hosts who are Superhosts today performed over the last 3 years. Applying today's tier to every old booking is the point.
The third case shows that Type 1 is a reporting choice as much as a storage shortcut. The same tier column can be right to overwrite for one audience and wrong for another. What decides it is the question the report answers: how did these entities perform, or what was true when each event happened.

The cost of overwriting

Type 1 is the cheapest rule to run. The load compares incoming values with stored ones and updates the rows that differ. The dimension's row count equals the number of entities, so joins stay small and counting hosts is COUNT(*).

The cost arrives later, in other tables. Any table computed from the old value keeps showing it until rebuilt. Suppose a nightly aggregate, agg_revenue_by_city, holds 900 of revenue under Osaka from host 6102's bookings. Support then learns she hosts in Kyoto and corrects city with a Type 1 update. The dimension says Kyoto, the aggregate still says Osaka, and a dashboard reading the aggregate disagrees with a query on the star. A Type 1 change to any column that aggregates group by has to trigger a rebuild of those aggregates across their full history.

The other cost is trust. For a display field, nobody notices an overwrite. For a column that feeds finance or compensation, an unexplained restatement of a closed month becomes an incident.
✓Do
  • Use Type 1 for corrections, where the old value was never true.
  • Rebuild every aggregate grouped by a column after overwriting it.
  • Record which columns are Type 1 in the table's documentation.
✗Don't
  • Overwrite a column that finance, billing or commission reports group by.
  • Assume history is safe because the fact table was left untouched.
  • Pick Type 1 for a tracked attribute because the load is shorter to write.
TIP
A test for any column: after it changes, should last quarter's report change too? If yes, overwrite it. If the report must stay as published, Type 1 is the wrong rule for that column.
Multiple Choice

A host dimension has these 4 columns. Which one should the load overwrite with Type 1?

Type 1 keeps the dimension small and the load short, and it gives up the past. When a past value has to survive, the table needs somewhere to keep it, and the roomiest place is a second row.

Type 2: Preserve Full History

Daily Life
Interviews
Type 2 keeps the old row and adds a new one. Each change to a tracked attribute produces a fresh row with its own surrogate key, and the row it replaces is marked as closed. One row now means one version of a host, valid for a stated window of time.
dim_host
host_keyPKBIGINT
host_idBIGINT
host_nameVARCHAR
tierVARCHAR
valid_fromDATE
valid_toDATE
is_currentBOOLEAN
fact_booking
booking_idPKBIGINT
host_keyFKBIGINT
booking_dateDATE
amountDECIMAL(10,2)

3 columns do the bookkeeping. valid_from is the first day a version applies. valid_to is the day the next version takes over, so a version covers valid_from up to but excluding valid_to. is_current flags the open version. The open row carries valid_to = 9999-12-31, a far-future date that lets one range condition match open and closed rows alike.

host_keyhost_idtiervalid_fromvalid_tois_current
1014417Standard2023-06-122025-04-01false
1044417Superhost2025-04-019999-12-31true
1025230Superhost2022-09-059999-12-31true

Marta now has 2 rows. host_id 4417 appears twice, which is why the natural key can no longer be the primary key. The surrogate host_key identifies a version, and host_id ties the versions of one host together.

What the load does on a change

When the nightly load finds that host 4417's incoming tier differs from her open row, it runs 2 statements. The first closes the open version.
UPDATE dim_host
SET
valid_to = DATE '2025-04-01',
is_current = FALSE
WHERE host_id = 4417
AND is_current = TRUE
The second statement inserts the new version under a new surrogate key, starting on the day the old one ended.
INSERT INTO dim_host (host_key, host_id, host_name, tier, valid_from, valid_to, is_current)
VALUES (104, 4417, 'Marta Reis', 'Superhost', DATE '2025-04-01', DATE '9999-12-31', TRUE)
One version ends on the date the next begins, and the end date is excluded. The windows for a host therefore never overlap and never leave a gap, and any date maps to exactly one version.

How facts find the right version

The source system sends each booking with a host_id and a date. The fact load translates that pair into a host_key by finding the version whose window contains the booking date.

SELECT
s.booking_id,
h.host_key,
s.booking_date,
s.amount
FROM staged_booking AS s
JOIN dim_host AS h
ON s.host_id = h.host_id
AND s.booking_date >= h.valid_from
AND s.booking_date < h.valid_to

Bookings 9001 and 9002 happened in February and March, so they keep host_key = 101, the Standard version. Booking 9004 on April 10 receives 104. The date logic runs once, at load time. After that, reports use the same equality join on host_key as before, and the first-quarter report returns Standard 800 and Superhost 400 no matter when it runs.

Both views from one table

A Type 2 dimension still answers as-is questions. Join each fact to its version, then hop through host_id to the same host's current row and group by that row's tier.

SELECT
cur.tier AS tier_today,
SUM(b.amount) AS revenue
FROM fact_booking AS b
JOIN dim_host AS ver
ON b.host_key = ver.host_key
JOIN dim_host AS cur
ON ver.host_id = cur.host_id
AND cur.is_current = TRUE
GROUP BY cur.tier
On the 4 bookings from the opening example, this query returns a single line, Superhost 1800, because both hosts hold that tier today. The as-is view costs one extra join.
Rules for querying and loading a Type 2 table
  • ▸Count hosts with COUNT(DISTINCT host_id) or a filter on is_current. COUNT(*) counts versions.
  • ▸Look up fact keys by event date. is_current is for as-is reports, and using it in the fact load mislabels any booking that arrives late.
  • ▸Expect growth. 40,000 hosts with 3 tracked changes each occupy 160,000 rows.
Multiple Choice

Host 4417 has version 101 (Standard, 2023-06-12 up to 2025-04-01) and version 104 (Superhost, from 2025-04-01). A booking dated March 28, 2025 is delayed in the source system and reaches the fact load on April 3. Which host_key belongs on its fact row?

Type 2 answers what was true at the time for every fact, at the price of a longer load and a table where a host and a row are different things. Some requirements need less: a single earlier value, kept beside the current one.

Type 3: Keep Previous Value

Daily Life
Interviews

Type 3 keeps history in a column. The dimension gains a previous_ column next to the tracked attribute, and usually a date for when the switch happened. On a change, the current value moves into the previous column and the new value takes its place. The table stays at one row per entity.

A change that hits everyone at once

On July 1, 2025 the marketplace redraws its sales regions. Iberia is folded into a new Southern Europe region, and DACH becomes Central Europe. Regional managers hold targets set under the old map and need this year's reports under both maps while they adjust. Every host changes on the same day, for the same reason, and the business wants the old and new labels side by side.
UPDATE dim_host
SET
previous_region = region,
region = 'Southern Europe',
region_changed_on = DATE '2025-07-01'
WHERE region = 'Iberia'

In standard SQL, each SET expression reads the row as it was before the statement ran, so previous_region receives Iberia. The tables in this section use a one-row-per-host dim_host so the Type 3 columns stand alone.

host_idhost_nameregionprevious_regionregion_changed_on
4417Marta ReisSouthern EuropeIberia2025-07-01
5230Jonas WeberCentral EuropeDACH2025-07-01
Read one row as: this host, with the region they belong to now and the region they belonged to before the latest change. Both values sit on the same row, so both reach every fact through the ordinary join.
SELECT
d.region,
d.previous_region,
SUM(f.amount) AS total_revenue
FROM fact_booking AS f
JOIN dim_host AS d
ON f.host_key = d.host_key
GROUP BY d.region, d.previous_region
regionprevious_regiontotal_revenue
Southern EuropeIberia1400
Central EuropeDACH400
This is the report Type 3 exists for. All of Marta's bookings, February through April, total 1400 under Iberia and the same 1400 under Southern Europe. A Type 2 table gives each booking one region, the one in force on its date, so totaling everything under the old map takes a second join pinned to a date. Type 3 treats the 2 values as alternate labels for the same facts.

The limit of a single previous column

The column holds one earlier value. Suppose Southern Europe is renamed Mediterranean in 2026. The update moves Southern Europe into previous_region, and Iberia is gone.

Afterregionprevious_region
Initial loadIberiaNULL
July 2025 redrawSouthern EuropeIberia
2026 renameMediterraneanSouthern Europe

Adding previous_region_2 postpones the problem and widens the table for every tracked attribute. A second limit is per-fact truth. Which region applied to a given booking is missing from the row. Comparing booking_date with region_changed_on recovers it for the latest change and for nothing earlier.

Type 2 answers
  • Which value was in force when this fact happened?
  • How many times has this host changed, and when?
  • What did the dimension look like on a given past date?
Type 3 answers
  • What do all facts total under the previous labels?
  • Which entities moved in the latest change?
  • How do the old and new groupings compare over one period?
Type 3 fits a narrow profile. Changes are rare and planned, they often hit many rows on one date, and people want to compare 2 labelings of the same facts during a transition. Hosts changing tier at different times, several times each, are the opposite profile.
Multiple Choice

A streaming service keeps plan and previous_plan on its one-row-per-member dimension. A member moves from Basic to Standard in 2024, then from Standard to Premium in 2025. Finance asks how much this member paid while on Basic. What can the dimension contribute?

A previous-value column is the smallest history a dimension can hold. It works while the question is old labels against new labels, and it fails as soon as someone asks about the value before last.

Choosing Your Strategy

Daily Life
Interviews

The choice is made per column, and one dimension usually mixes rules. On dim_host, payout_email can be Type 1, tier Type 2 and region Type 3, all in the same table. A dimension is called Type 2 when at least one of its columns creates new rows.

PropertyType 1Type 2Type 3
On a changeReplace the valueClose the row, add a rowShift the value into a previous column
One row meansThe entity as known todayOne version, valid for a windowThe entity today plus one earlier value
Rows per entity11 per version1
History keptNoneEvery version, with datesThe latest change only
Past facts showToday's valueThe value at event timeEither label, across all facts
Breaks whenA closed period must stay fixedThe attribute changes dailyA second change arrives

3 questions for each column

Ask them in this order
  • Does any report group, filter or price facts by this column? If none does, choose Type 1 and stop.
  • After the value changes, must reports on closed periods keep their published numbers? If yes, the column needs Type 2.
  • Is the change a rare, planned relabeling, with people wanting all facts under both old and new labels? That is the Type 3 case.
  • If reports group by the column but only ever want today's labels (as-is), Type 1 still fits. If that need may change, see When you are unsure below.
The second question separates as-was reporting from as-is reporting. As-was shows each fact with the attribute value from its own date, and finance, billing and compensation nearly always require it. As-is shows all facts under today's values, which suits questions about the entities themselves, such as how today's Superhosts grew over time.

Mixing rules on one table

Mixing has one mechanical consequence. When a Type 1 column changes on a table that also has Type 2 columns, the update must reach every version of that entity. If Marta's host_name is corrected, rows 101 and 104 both receive the fix and no new version is created. A name that differed between versions would split her bookings in any report grouped by name.

When you are unsure

The 2 main rules differ in what can be undone later. A Type 2 dimension can always serve as-is questions through its current rows. A Type 1 dimension can never serve as-was questions, because the old values were discarded and no backfill can invent them. For a column that reports group by, with an uncertain future, Type 2 is the reversible choice. Its extra rows cost storage, and a missing history cannot be bought back at any price.
One case argues against Type 2: an attribute that changes very often. A host's average review score moves after every review. Tracking it as Type 2 would add a dimension row per review, and the dimension would grow like a fact table. A value that changes with events is a measurement, and it belongs in a fact table, such as a periodic snapshot of each host's score.
A customer dimension grows upStep 1
>

You own the warehouse at a subscription software company. `dim_customer` has one row per customer and is overwritten every night. `fact_invoice` has one row per invoice. 2 requests arrive this year.

dim_customer
customer_keyBIGINTPKcustomer_idBIGINTemailVARCHARplanVARCHARterritoryVARCHAR
fact_invoice
invoice_idBIGINTPKcustomer_keyBIGINTFKinvoice_dateDATEamountDECIMAL(10,2)

Finance wants monthly revenue by plan, using the plan each customer was on when each invoice was issued. Customers switch plans whenever they like, some of them several times a year. How should `plan` be tracked?

Write the chosen rule beside each column in the table's documentation. The next person to build a report will read it to learn whether a number can change after it has been published.
PUTTING IT ALL TOGETHER

> A food delivery marketplace keeps a restaurant dimension. Restaurants negotiate new commission tiers a few times a year, operations redraws delivery zones once each January, owners update phone numbers weekly, and star ratings move with every order. Finance must reproduce any closed month's commission revenue, and zone managers want this year's orders under last year's zones and this year's.

Commission tier is Type 2: each order's fact row carries the key of the restaurant version open on the order date, so a closed month's commission revenue reproduces exactly.
Delivery zone is Type 3: the January shift, like the phone fix, is applied to every version row of each restaurant, so all its orders carry the same zone and previous_zone and one query totals the year's orders under either map.
Phone number is Type 1, and the update is applied to every version row of the restaurant so no new version appears.
Star rating changes with events, so it is stored as a measurement in a snapshot fact table and kept out of the dimension's tracked columns.
Without the Type 2 rows, the first renegotiated tier would have relabeled every earlier order, which is the history problem the lesson opened with.
KEY TAKEAWAYS
A fact stores a pointer to a dimension row, so overwriting that row changes what every past fact shows.
Type 1 replaces the value. Use it for corrections and for columns no report groups by, and rebuild any aggregate built on the old value.
Type 2 adds a dated row per change under a new surrogate key. Facts are keyed to the version open on their event date, so closed periods stay fixed.
Type 3 adds a previous-value column. It serves one planned relabeling compared both ways, and it loses everything before the latest change.
The rule is chosen per column by asking what past facts must show after a change. When unsure about a reported column, Type 2 is the choice that can be undone.

Decide what a dimension remembers when a value changes: overwrite it, version it, or keep the one before.

Category
Data Modeling
Difficulty
intermediate
Duration
17 minutes
Challenges
12 hands-on challenges

Topics covered: The History Problem, Type 1: Overwrite Old Value, Type 2: Preserve Full History, Type 3: Keep Previous Value, Choosing Your Strategy

Lesson Sections

  1. 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 The quarter was closed, no booking was added or edited, and the answer still moved. Marta's 2 first-quarter bookings,

  2. Type 1: Overwrite Old Value

    Type 1 is the rule from the previous section, applied on purpose. When a source value changes, the load updates the dimension row in place and discards the old value. The table keeps one row per entity, the surrogate key stays the same, and no fact row is touched. Read one row of a Type 1 dimension as: this host, as the business knows them right now. That meaning covers every column in the row. A report that joins to it describes all of history using today's values, a style called as-is reportin

  3. Type 2: Preserve Full History

    Type 2 keeps the old row and adds a new one. Each change to a tracked attribute produces a fresh row with its own surrogate key, and the row it replaces is marked as closed. One row now means one version of a host, valid for a stated window of time. What the load does on a change When the nightly load finds that host 4417's incoming tier differs from her open row, it runs 2 statements. The first closes the open version. The second statement inserts the new version under a new surrogate key, star

  4. Type 3: Keep Previous Value

    A change that hits everyone at once On July 1, 2025 the marketplace redraws its sales regions. Iberia is folded into a new Southern Europe region, and DACH becomes Central Europe. Regional managers hold targets set under the old map and need this year's reports under both maps while they adjust. Every host changes on the same day, for the same reason, and the business wants the old and new labels side by side. In standard SQL, each SET expression reads the row as it was before the statement ran,

  5. Choosing Your Strategy

    3 questions for each column The second question separates as-was reporting from as-is reporting. As-was shows each fact with the attribute value from its own date, and finance, billing and compensation nearly always require it. As-is shows all facts under today's values, which suits questions about the entities themselves, such as how today's Superhosts grew over time. Mixing rules on one table When you are unsure The 2 main rules differ in what can be undone later. A Type 2 dimension can always