27. The medallion architecture 2: design choices
Inside the layers, three choices shape the design: where to clean and where to conform, how silver keeps history (slowly changing dimensions types 1 and 2), and whether gold is a star schema or a set of data products. Delta Lake's merge, time travel and schema evolution make each one practical.
The clip follows one customer through three changes: she moves from Utrecht to Rotterdam, has a typo in her email address corrected, then moves to Delft. On the left, a type 1 table overwrites: one row, always the latest. On the right, a type 2 table closes the current version and adds a dated new one for each move, and rewrites every version for the correction. Her three claims, counted by the city on the loss date, land in three cities under type 2 and all in Delft under type 1. Then time travel reads an earlier version, a new column is absorbed, and the same tables run on Fabric and on Databricks.
The idea: clean, conform, keep history, shape gold
Chapter 26 placed the steps; this chapter makes the choices inside them:
- Clean against conform. Cleaning fixes a source's own data (types, duplicates, impossible values) and belongs early in silver, once per source. Conforming puts several sources on shared keys and codes (both companies' customers, one loss-cause list) and belongs in silver too, but after cleaning, in its own tables, because it changes when the shared lists do.
- History in silver. A slowly changing dimension is a table whose rows change now and then. Type 1 overwrites: the table always says the latest, and the past is gone. Type 2 keeps a version per change with the dates it was valid, so a report can ask what was true on any day. Choose per attribute: type 2 where a report needs the past, type 1 for corrections, which were never true.
- Gold as a star or as products. One conformed star schema serves a BI team and the board; data products per domain serve many teams under contracts (chapters 23 and 24); a star built on products serves both.
Delta Lake makes these practical: MERGE applies changes (close a version, insert the next) in one commit, time travel reads any earlier version of a table, and schema evolution adds a column without rewriting the table, while schema enforcement refuses data that does not fit.
A worked example: one customer, three changes
Sanne de Vries moves twice and has her email corrected once. Type 2 for the city and type 1 for the email gives 3 versions; type 1 for both gives 1. Her claim of 2026-04-20 happened while she lived in Rotterdam: type 2 counts it there, type 1 in Delft.
| City | Valid from | Valid to | |
|---|---|---|---|
| Utrecht | sanne.devries@example.nl | 2024-01-15 | 2026-03-01 |
| Rotterdam | sanne.devries@example.nl | 2026-03-01 | 2026-08-15 |
| Delft | sanne.devries@example.nl | 2026-08-15 | – |
CREATE SCHEMA silver;
CREATE TABLE silver.customer_history (
customer_id STRING NOT NULL, name STRING, city STRING, email STRING,
valid_from DATE NOT NULL, valid_to DATE, is_current BOOLEAN NOT NULL
) USING DELTA;
CREATE TABLE silver.claims (claim_ref STRING NOT NULL, customer_id STRING NOT NULL, loss_date DATE NOT NULL, amount DECIMAL(12,2)) USING DELTA;
INSERT INTO silver.claims VALUES
('CL-2025-00311', 'C-0042', DATE '2025-06-12', 1850.00),
('CL-2026-00140', 'C-0042', DATE '2026-04-20', 3200.00),
('CL-2026-00388', 'C-0042', DATE '2026-09-03', 640.00);
INSERT INTO silver.customer_history VALUES ('C-0042', 'Sanne de Vries', 'Utrecht', 'sanne.devries@exmaple.nl', DATE '2024-01-15', NULL, true);
MERGE INTO silver.customer_history AS t
USING (
SELECT u.customer_id AS merge_key, u.* FROM (VALUES ('C-0042', 'Sanne de Vries', 'Rotterdam', 'sanne.devries@exmaple.nl', DATE '2026-03-01')) AS u(customer_id, name, city, email, changed_on)
UNION ALL
SELECT NULL AS merge_key, u.* FROM (VALUES ('C-0042', 'Sanne de Vries', 'Rotterdam', 'sanne.devries@exmaple.nl', DATE '2026-03-01')) AS u(customer_id, name, city, email, changed_on)
JOIN silver.customer_history h ON h.customer_id = u.customer_id AND h.is_current AND h.city <> u.city
) AS s
ON t.customer_id = s.merge_key AND t.is_current
WHEN MATCHED AND t.city <> s.city THEN UPDATE SET valid_to = s.changed_on, is_current = false
WHEN NOT MATCHED THEN INSERT (customer_id, name, city, email, valid_from, valid_to, is_current)
VALUES (s.customer_id, s.name, s.city, s.email, s.changed_on, NULL, true);
UPDATE silver.customer_history SET email = 'sanne.devries@example.nl' WHERE customer_id = 'C-0042';
MERGE INTO silver.customer_history AS t
USING (
SELECT u.customer_id AS merge_key, u.* FROM (VALUES ('C-0042', 'Sanne de Vries', 'Delft', 'sanne.devries@example.nl', DATE '2026-08-15')) AS u(customer_id, name, city, email, changed_on)
UNION ALL
SELECT NULL AS merge_key, u.* FROM (VALUES ('C-0042', 'Sanne de Vries', 'Delft', 'sanne.devries@example.nl', DATE '2026-08-15')) AS u(customer_id, name, city, email, changed_on)
JOIN silver.customer_history h ON h.customer_id = u.customer_id AND h.is_current AND h.city <> u.city
) AS s
ON t.customer_id = s.merge_key AND t.is_current
WHEN MATCHED AND t.city <> s.city THEN UPDATE SET valid_to = s.changed_on, is_current = false
WHEN NOT MATCHED THEN INSERT (customer_id, name, city, email, valid_from, valid_to, is_current)
VALUES (s.customer_id, s.name, s.city, s.email, s.changed_on, NULL, true);
ALTER TABLE silver.customer_history ADD COLUMNS (preferred_language STRING);
-- History, the point-in-time join gold reads, and time travel
SELECT customer_id, city, email, valid_from, valid_to, is_current FROM silver.customer_history ORDER BY valid_from;
SELECT h.city, COUNT(*) AS claims, SUM(c.amount) AS incurred
FROM silver.claims c
JOIN silver.customer_history h ON h.customer_id = c.customer_id
AND c.loss_date >= h.valid_from AND (h.valid_to IS NULL OR c.loss_date < h.valid_to)
GROUP BY h.city ORDER BY h.city;
SELECT city, email FROM silver.customer_history VERSION AS OF 2 WHERE is_current;Time travel reads the table at version 2, after the first move: Rotterdam, with the old email, as it was. The schema change adds preferred_language as version 5, and the history and gold's point-in-time join run unchanged.
Why it matters for Alex
After the merger, the board will ask for claims by region, and half of Kestrel's customers will have moved since their claims. Without history in silver, every claim is counted where the customer lives today, and the regional loss ratios quietly shift each time someone moves. And when a report looks wrong, time travel shows the table as it was when the report ran.
Where it goes wrong
- Type 2 for everything. A corrected typo becomes a version, as if the wrong address had once been true, and tables grow with noise.
- Type 1 for everything. The past is rewritten every night, and last year's report cannot be reproduced.
- Conforming in gold. Each gold table maps the codes its own way, and two reports disagree on what "water damage" covers.
- Evolving the schema by accident. Turning on automatic schema merging everywhere lets a typo in a source column add a new column to silver. Evolve on purpose, under a contract.
Exercises
The lab checks each one against facts written down in advance, so any answer the brief allows passes. A pass is kept in this browser.
Type 1 or type 2?
For each attribute's change, choose how silver should keep it.
History kept through three changes
Sanne de Vries's three changes have reached silver. Choose the city each claim is counted under.
Absorbed or breaking?
Each line is a change in the customer feed's schema. Choose what happens to silver and to gold, which joins on customer_id, city, valid_from and valid_to.
preferred_language
fraud_flag
city to town
amount as text, such as "1,200"
valid_from
Gold as a star schema or as data products
What should Harbour Mutual's gold layer be? Pass all 2 situations to complete it.
One BI team of five serves the board and the finance analysts, all in Power BI. No other team reads the lakehouse yet.
On Azure
The same design, on each platform (decision D6: both, honestly):
- Microsoft Fabric: lakehouse tables are Delta, so MERGE, time travel and ALTER TABLE run in Fabric's Spark notebooks; the SQL analytics endpoint and the Warehouse read the same tables in T-SQL, and Power BI's Direct Lake mode reads gold without importing it.
- Azure Databricks: the same statements run on Delta tables in Unity Catalog; Lakeflow Spark Declarative Pipelines' AUTO CDC keeps type 1 or type 2 history from a change feed for you, handling changes that arrive out of order.
- Time travel reaches back as far as the table's log and data files are kept: VACUUM removes old files after a retention period (seven days by default), so set it to how far back you need to read.
Whichever platform runs silver, keep the history rules (which attributes are type 2) in one place, next to the contract.
Take it to work
Silver and gold design choices
Decide where to clean and conform, how history is kept, and what gold is.
Clean and conform
- What is cleaned per source
- What is conformed on shared keys and code lists, and where
History
- Each attribute: type 1 or type 2, and the report that needs it
Schema changes
- Which changes are absorbed, and who approves the others
Gold
- A star, data products, or both, and for which readers
Platform
- Fabric, Databricks or both, and how far back time travel must reach
Tools in this chapter
- Model studio · Draw conceptual, logical and physical models, generate DDL for PostgreSQL, Spark SQL and T-SQL, and run it on Harbour Mutual's data in your browser.
Terms taught here: Slowly changing dimensionTime travelMERGE