Medallion Architecture Late-Arriving Dimensions with SCD Type 2: An Implementation Tutorial

Handle late-arriving dimensions with event-time SCD Type 2 joins, unknown members, deduplicated writes and replay checks across medallion layers.

Medallion Architecture Late-Arriving Dimensions with SCD Type 2: An Implementation Tutorial

Author: jackey.ye · Updated: 2026-11-25

Resolve late-arriving dimensions by joining each fact to the dimension version whose valid_from/valid_to interval contains the fact's event timestamp, falling back to a real unknown-member row when no version matches, and applying corrections through an idempotent MERGE keyed on a deterministic surrogate key.

This tutorial covers late-arriving dimension changes and late facts in a medallion pipeline. It does not cover generic schema evolution — added, renamed or widened columns — which has a different cause and a different fix; that boundary is drawn explicitly below.

Five entities recur throughout:

  • Fact event — a measured business occurrence carrying an event_ts in event time, not load time.

  • Dimension version — one row of a type 2 slowly changing dimension (SCD2), valid over a half-open interval.

  • Surrogate key — a version-specific integer or hash that identifies one dimension row, never the member.

  • Unknown member — a real dimension row with a reserved key that absorbs facts whose member cannot be resolved.

  • Batch/replay identifier — the label that lets a repeated load be recognized as already applied.

The layer-level acceptance checks that surround this work live in the medallion implementation checklist hub.

What Is the Late-Arriving Dimension Problem in a Medallion Architecture?

A late-arriving dimension problem exists when a fact's event timestamp falls inside a validity window that the dimension table does not yet contain, or contains in a form that later changes. Three variants matter, and they need different handling.

  1. The version is missing. A fact for customer C-1042 is dated 2026-03-04, but the dimension only holds a version starting 2026-05-01. The member existed at event time; the record of it arrived late.

  2. The version arrives with a past effective date. A region reassignment effective 2026-02-15 lands in the pipeline on 2026-06-02. The existing interval must be split, not appended.

  3. The version is corrected after the fact was written. A misspelled segment attribute is fixed retroactively, so the gold row already joined to the old version is now wrong.

Medallion layering makes the failure visible at a specific place. Bronze holds raw events as received. Silver holds conformed dimensions and facts. Gold holds the joined model — and the join is where a wrong version produces a plausible but incorrect number with no error. A revenue-by-region report built on a current-row join will silently reassign historical sales to the new region, which is exactly the distortion Microsoft describes for type 1 changes: the rollup behaves as if the member was always assigned to the new region.

Concrete case used below: fact order_id = 88117, event_ts = 2026-03-04, customer_id = C-1042. The customer moved from region APAC to EMEA effective 2026-02-15, and that change reached the warehouse on 2026-06-02.

How Do You Join a Fact to the SCD Type 2 Version Valid at Its Event Time?

Join on the interval, not on the current flag: fact.event_ts >= dim.valid_from AND fact.event_ts < dim.valid_to, with valid_to exclusive and set to a far-future sentinel rather than NULL for the open version.

Why the sentinel instead of NULL. A predicate containing dim.valid_to > fact.event_ts evaluates to unknown when valid_to is NULL, so the open version drops out of the join and the fact loses its match. Replacing NULL with a sentinel such as 9999-12-31 keeps the predicate two-sided and index-friendly. dbt's snapshot implementation exposes the same trade-off directly: dbt_valid_to is NULL for current records by default, and the dbt_valid_to_current config exists to substitute a custom indicator such as a future date instead.

Why a surrogate key is mandatory. A natural key repeats across versions once history is stored, so it cannot identify a row. Microsoft's dimensional modeling guidance states that for SCD type 2, a surrogate key is required because there will be duplicate natural keys when multiple versions are stored.

Why is_current = true is the wrong default. It answers "what is this member's state now", not "what was it at event time". It is correct only when the question is genuinely as-of-now — a current pipeline health dashboard, for example — and wrong for any historical measure.

Example configuration — validate in your target environment.

SELECT
      f.order_id,
      f.event_ts,
      f.amount,
      COALESCE(d.customer_sk, -1)  AS customer_sk,
      COALESCE(d.region, 'UNKNOWN') AS region
  FROM silver.fct_orders        AS f
  LEFT JOIN silver.dim_customer AS d
         ON d.customer_id = f.customer_id
        AND f.event_ts   >= d.valid_from
        AND f.event_ts    < d.valid_to;
  

Expected output shape: exactly one row per fact, carrying exactly one dimension version. If the row count exceeds the fact count, the dimension has overlapping intervals for some key — fix the intervals before trusting the join. The LEFT JOIN plus COALESCE is what routes unmatched facts to the unknown member instead of dropping them.

How Do You Splice a Late-Arriving Dimension Change Into Existing History?

Splice, don't append: close the version that was open at the new effective date by setting its valid_to to the new valid_from, then insert the new version with that same valid_from and the sentinel valid_to. The result is three rows where there was one — the untouched earlier history, the shortened prior version, and the new version.

For C-1042, the pre-splice table holds one row: APAC, valid_from = 2025-01-01, valid_to = 9999-12-31. The late change carries effective_date = 2026-02-15 and region = EMEA. After the splice:

customer_sk

customer_id

region

valid_from

valid_to

is_current

5101

C-1042

APAC

2025-01-01

2026-02-15

false

5102

C-1042

EMEA

2026-02-15

9999-12-31

true

The ordering hazard. If two late changes for the same key arrive in the same batch, applying them in arrival order can close the wrong row and produce overlapping or inverted intervals. Sort the staged source by customer_id, effective_date before the MERGE, and keep only the latest change per key per batch.

The MERGE constraint. Delta's MERGE fails with DELTA_MULTIPLE_SOURCE_ROW_MATCHING_TARGET_ROW_IN_MERGE when more than one source row matches the same target row, and the documentation's remedy is to preprocess the source table to eliminate the possibility of multiple matches. Databricks' SCD type 2 example stages the update as a union of a close-row set and an insert-row set, then applies both in one MERGE — the pattern below follows it.

Example configuration — validate in your target environment.

WITH staged AS (
      SELECT customer_id, region, effective_date,
             ROW_NUMBER() OVER (PARTITION BY customer_id
                                ORDER BY effective_date DESC) AS rn
      FROM bronze.customer_changes
      WHERE batch_id = :batch_id
  )
  MERGE INTO silver.dim_customer AS t
  USING (SELECT * FROM staged WHERE rn = 1) AS s
  ON  t.customer_id = s.customer_id
  AND t.is_current  = true
  AND s.effective_date > t.valid_from
  WHEN MATCHED THEN UPDATE SET
      t.valid_to   = s.effective_date,
      t.is_current = false
  WHEN NOT MATCHED THEN INSERT
      (customer_sk, customer_id, region, valid_from, valid_to, is_current)
  VALUES
      (xxhash64(s.customer_id, s.effective_date), s.customer_id, s.region,
       s.effective_date, TIMESTAMP '9999-12-31 00:00:00', true);
  

Validation query. Run this after every dimension load; both counts must be zero.

SELECT customer_id, COUNT(*) AS bad_pairs
  FROM (
      SELECT a.customer_id
      FROM silver.dim_customer a
      JOIN silver.dim_customer b
        ON a.customer_id = b.customer_id
       AND a.customer_sk <> b.customer_sk
       AND a.valid_from < b.valid_to
       AND b.valid_from < a.valid_to
  ) overlaps
  GROUP BY customer_id;
  

A gap check follows the same shape: for each key, the maximum valid_to of any non-current row must equal the valid_from of the next version, and exactly one row per key must carry is_current = true.

When Should a Fact Get the Unknown Member Instead of Waiting for the Dimension?

Assign the unknown member when the fact is additive and the dimension is expected to arrive within a defined correction window; wait when the dimension is authoritative and the fact is non-additive.

The unknown member exists so a fact can be loaded without blocking on a dimension that may never arrive. The trade-off is explicit: assigning unknown preserves fact completeness and pipeline liveness but loses attribution until a correction pass runs; waiting preserves attribution but stalls the fact and can cascade into downstream SLA misses.

Microsoft's dimension guidance describes inserting rows that represent missing, unknown, N/A or error states, and assigns them reserved surrogate key values — -1 for a lookup failure and 0 for a member missing in the source system. The important structural point is that the unknown member must be a real row in the dimension table, not a NULL foreign key. A NULL breaks the interval join, hides the fact from the model, and defeats the very completeness the fallback was meant to protect.

Decision rule:

  • Use unknown when the fact is additive (amounts, counts, quantities), the dimension has a bounded correction window, and a later correction pass can re-point the fact. The fact lands now; attribution is repaired when the dimension arrives.

  • Wait when the fact is non-additive or the dimension is the system of record for a regulated attribute, and a wrong attribution is worse than a late one. Hold the fact in silver and alert on the age of the unmatched set.

  • Never use unknown as a permanent home for a member you know is missing from the source. That is a data quality defect, not a late arrival, and it should fail a test rather than be absorbed.

Whichever route you take, record the unmatched facts so the correction pass has a work list: a dim_resolved = false flag on the fact, or a side table of (fact_key, natural_key, event_ts) rows.

How Do You Replay Corrections Idempotently Without Duplicating Facts or History Rows?

Replay is safe only when a second run of the same batch produces the same rows. Get there with two keys: a deterministic dimension surrogate key derived from the natural key plus valid_from, so a replayed change regenerates the identical key and its MERGE matches instead of inserting; and a fact-side replay identifier (batch ID plus event timestamp) that the fact MERGE matches on, so a repeated write is a no-op. Deduplicate the source before either MERGE — Databricks documents that MERGE fails with DELTA_MULTIPLE_SOURCE_ROW_MATCHING_TARGET_ROW_IN_MERGE when several source rows match one target row, and that duplicates inside the new dataset are inserted rather than collapsed, so the merge guidance requires deduplicating the source first. On Iceberg, the equivalent guarantee comes from the format's serializable isolation and atomic commit: writes add and remove files in a single operation and are never partially visible. The replay test itself is a re-run of a known batch against a copy, asserting row counts and key values are unchanged; the medallion implementation checklist hub carries that replay check as an acceptance gate alongside the environment-separation requirement.

How Is This Different From Generic Schema Evolution?

Schema evolution changes the table's columns; late-arriving dimensions change the table's rows and their validity intervals. The fixes do not substitute for each other, and a pipeline can have one without the other.

A schema evolution event is a new attribute, a renamed column, a widened type, or a tightened nullability. Its fix lives in the write path and the migration: a schema-evolution-aware writer, a versioned source contract, and a coordinated release. Delta's own behavior table makes the mechanical difference concrete — when the target has key, old_value and the source has key, new_value, a MERGE without schema evolution throws an error because the target column old_value is not in the source, while with schema evolution enabled the table schema is widened to (key, old_value, new_value) and existing matches keep old_value unchanged. That is a column-level problem with a column-level answer.

A late-arriving dimension event is a row whose valid_from precedes the load time. No column is added or renamed; the table's shape is fine. What is wrong is the interval coverage, and the fix is the splice plus the interval join plus idempotent replay.

The practical consequence: enabling schema evolution will not repair a mis-joined historical fact, and a correct interval join will not absorb a producer that added a required column without a default. Diagnose which one you have before choosing a remedy. The medallion architecture schema evolution guide covers the column-level problem, its contract versioning and its rollback path.

Comparison Table: Handling Choices for Late-Arriving Dimensions

The table below is a standalone reference: each row is a handling choice, and the last two columns tell you when it is right and what breaks when it is misapplied.

Handling choice

What it preserves

What it costs

Right choice when

Failure mode if misapplied

Join on the current row (is_current = true)

Simplicity; one row per member

No historical attribution

The question is genuinely as-of-now

Historical facts silently reassigned to the newest attribute value

Event-time interval join

Correct as-of-event version per fact

Requires surrogate key, sentinel valid_to, overlap-free intervals

Any historical measure by a changing attribute

Fan-out and double counting when intervals overlap

Unknown-member fallback

Fact completeness and pipeline liveness

Attribution deferred to a correction pass

Additive fact; dimension expected inside the correction window

Permanent blind spot if used for genuinely missing members

Wait for the dimension

Exact attribution, no repair pass

Fact latency; SLA risk downstream

Non-additive fact or authoritative dimension

Stalled pipeline and cascading SLA misses

Splice plus idempotent replay

Correct history and repeatable loads

Ordering discipline; deduplicated source before MERGE

Late change with a past effective date

Overlapping or inverted intervals when applied out of order

Full rebuild from bronze

Guaranteed consistency with raw evidence

Compute time proportional to history

Interval logic changed, or corruption is widespread

Recurring cost and long outages if used as the routine fix

Implementation Checklist: Environment, Prerequisites, and Expected Output

Work the items in order; each one names its environment requirement, its prerequisite, the action, and the acceptance check that tells you it is done.

Example configuration — validate in your target environment.

  1. Choose and pin the table format. Environment: Delta Lake on a Databricks Runtime, or Apache Iceberg v2 or later. Prerequisite: a catalog and object storage you control. Action: record the format and engine version in the pipeline repository. Expected output: one documented choice, because it determines the idempotency mechanism available in items 5 and 6.

  2. Create the dimension table. Environment: same engine as item 1. Prerequisite: the natural key identified. Action: create silver.dim_customer with customer_sk, customer_id, attributes, valid_from, valid_to (sentinel default), and is_current. Expected output: DESCRIBE shows all five column groups and no nullable valid_to.

  3. Seed the unknown member. Prerequisite: item 2 complete. Action: insert one row with customer_sk = -1, customer_id = 'UNKNOWN', valid_from = 1900-01-01, valid_to = 9999-12-31, is_current = true. Expected output: SELECT COUNT(*) FROM silver.dim_customer WHERE customer_sk = -1 returns 1.

  4. Build the interval join. Environment: silver and gold schemas. Prerequisite: items 2 and 3. Action: implement the half-open interval join with LEFT JOIN and COALESCE to -1. Expected output: gold row count equals fact row count, and the count of customer_sk = -1 rows is reported per run.

  5. Implement the splice MERGE. Prerequisite: a deduplicated, effective-date-ordered change source. Action: apply the close-and-insert MERGE from the splice section. Expected output: no DELTA_MULTIPLE_SOURCE_ROW_MATCHING_TARGET_ROW_IN_MERGE error, and exactly one is_current = true row per customer_id.

  6. Implement the fact MERGE with a replay identifier. Prerequisite: a stable fact natural key (order_id plus event_ts). Action: MERGE facts on that key and record batch_id. Expected output: re-running the same batch_id leaves the fact row count unchanged.

  7. Run the overlap and gap validation. Prerequisite: item 5. Action: execute the overlap query and the gap check. Expected output: both return zero rows for every customer_id.

  8. Run the replay test against a copy. Prerequisite: a non-production environment with a copy of the affected tables. Action: replay a known batch twice and compare. Expected output: identical row counts, identical customer_sk values, and an unchanged maximum valid_from per key. The implementation checklist hub states the same replay test as an acceptance check and covers the environment-separation requirement around it.

Frequently Asked Questions

The five questions below cover the decisions readers most often get wrong after building the interval join: current-row joins, out-of-order changes, unknown-member representation, replay testing, and engine portability.

Why not just join the fact to the dimension's current row?

The current row reflects the member's state now, not at the fact's event time, so every fact whose dimension changed afterwards receives the wrong attribute. For order_id = 88117 dated 2026-03-04, a current-row join returns EMEA even though the customer was in APAC on that date. The interval join is the only way to retrieve the as-of-event version; the current-row join is correct only for reporting that is explicitly as-of-now.

What happens if two late dimension changes arrive for the same key out of order?

Applying them in arrival order closes the wrong row and produces overlapping or inverted intervals, which then fan out the fact join. Sort the staged source by natural key and effective date, keep only the latest change per key per batch, and drive the MERGE from that deduplicated, ordered set. Run the overlap and gap validation after every load rather than discovering the damage in a gold report.

Should the unknown member be a NULL or a sentinel row?

A sentinel row. A NULL foreign key breaks the interval join, hides the fact from the model, and defeats the completeness the fallback was meant to protect. Microsoft's dimension guidance assigns reserved surrogate key values for these states — -1 for a lookup failure and 0 for a member missing in the source — and the row must physically exist in the dimension table so the join can match it.

How do you test replay without touching production data?

Run the batch twice against a copy in a separate environment, then assert that row counts, surrogate key values and the maximum valid_from per key are unchanged. The deterministic surrogate key makes the replayed dimension change produce the same key, and the fact-side replay identifier makes the second write a no-op. The implementation checklist hub states the same replay test and the environment separation it depends on.

Does this approach work on Iceberg as well as Delta Lake?

Yes. The interval join and splice logic are ordinary SQL and carry over unchanged; only the commit mechanics differ. Iceberg specifies serializable isolation, so readers always see a committed snapshot and a write is never partially visible, which gives the same retry-safe property that Delta's transaction identifiers provide. Keep the deterministic surrogate key either way — it is what makes a replayed change a no-op rather than a second version.

Next Steps

Put these in the tracker as binary gates rather than aspirations. Each one fails loudly if the mechanism is missing, so a green board means the pipeline is actually correct, not merely populated.

  • Every fact row resolves to exactly one dimension version, or to a sentinel row — never to zero rows and never to two.

  • No dimension key has overlapping intervals or gaps between valid_from and valid_to.

  • The unknown member exists as a real dimension row with a reserved surrogate key.

  • Re-running a known batch against a copy leaves row counts and surrogate keys unchanged.

  • Late changes are applied in effective-date order from a deduplicated source.

  • The open interval uses a sentinel upper bound, not NULL.

Run the overlap and gap validation after every dimension load, not only after incidents; the query is cheap and it is the only check that catches an out-of-order splice before it reaches gold. Keep the replay test in a separate environment so a failed assertion costs a pipeline run rather than a production table.

For the layer-level acceptance checks that sit around this work — bronze fidelity, silver validation, gold reconciliation — work through the medallion implementation checklist hub. When the change you are facing is a new or renamed column rather than a new validity interval, that is a different problem with a different fix; the medallion architecture schema evolution guide covers versioned contracts, rollback and replay for structural change.

Singdata sells a lakehouse platform, so it has a commercial interest in how you build these layers; evaluate any platform, including this one, against the gates above in your own environment.

For a related implementation check, see the data quality promotion gates.

Related Articles