Özer Cem KELAHMETKELAHMET
Articles · Medallion architecture

Medallion architecture in practice: bronze, silver and gold with quality gates and replay

Bronze, silver and gold is easy to draw and hard to run well. This guide builds all three layers in runnable SQL, routes five bad rows out of ten to a quarantine table, stops the run with a quality gate, then fixes a rule and replays from bronze without losing anything.

Download Markdown
At a glance
Reading time
13 min
Sections
10
Code examples
8
Tables
4
Sources
6
Published
23 Nov 2026
In 30 seconds
What changed
Spark 4.3.0 extends Declarative Pipelines
Why it matters
Medallion is not about three folders.
What to do
Make bronze append-only

The medallion architecture splits a lakehouse into three layers. Bronze keeps raw data exactly as it arrived. Silver holds cleaned, typed, deduplicated records. Gold holds business-ready tables such as daily revenue or customer metrics. The idea is simple, which is why it appears in almost every lakehouse design. The hard parts are the edges between layers: what counts as bad data, where it goes, when a run should stop, and how to rebuild silver and gold after you fix a rule.

This article builds a small medallion pipeline end to end. Ten raw order records land in bronze. A silver step casts types, applies six named rules, sends failures to a quarantine table and deduplicates. A quality gate stops the run when too many rows fail. A gold step aggregates revenue. Then we change one rule and replay from bronze. All SQL runs as written in DuckDB 2.0.1, and the same shapes translate directly to Spark SQL on Delta or Iceberg tables.

What happened

Spark 4.3.0 extends Declarative Pipelines (30 October 2026)

Apache Spark 4.3.0 was released on 30 October 2026, and its release notes describe it as the start of a quarterly feature-release cadence. For medallion pipelines the headline is in Spark Declarative Pipelines (SDP), the open-source framework in which you declare streaming tables and materialized views and Spark works out the order to update them. Spark 4.3 adds Slowly Changing Dimension Type 2 to SDP's Auto CDC flows through Python, SQL and Spark Connect, so a silver or gold table can keep the history of every record instead of overwriting it.

The SDP programming guide also documents the controls that matter for reprocessing: spark-pipelines run performs an incremental update by default, --full-refresh clears data and checkpoints for named datasets and recomputes them, --full-refresh-all resets the whole graph, and spark-pipelines dry-run catches syntax, analysis and graph errors without reading or writing data.

The three layers and their contracts

Each layer is a promise to the layer above it. Treat the promises as contracts, not folder names.

Table 1. The three layers and their contracts
Layer Contains Promise Typical write mode
Bronze Raw records plus ingestion metadata (file, time, offset) Nothing is lost or altered; you can always replay Append only
Silver Typed, validated, deduplicated entities Every row passed named rules; one row per business key Merge or overwrite by partition
Gold Aggregates and data products for consumers Numbers match agreed definitions Overwrite or incremental merge

A useful analogy is a restaurant kitchen. Bronze is the delivery bay: everything that arrives is logged and stored as delivered, even the bruised tomatoes. Silver is prep: ingredients are washed, sorted and the bad ones put aside with a note. Gold is the plated dish. If a recipe changes, you go back to prep, not to the farm.

Bronze: land everything, change nothing

Bronze stores each record as received, with metadata about where and when it arrived. Keep the payload as text or a semi-structured type so that a malformed record can never fail the load.

CREATE TABLE bronze_orders (
  ingest_id   INTEGER,
  source_file VARCHAR,
  ingested_at TIMESTAMP,
  payload     VARCHAR      -- the raw JSON line, untouched
);

Our batch, orders_2026-11-21.jsonl, has ten records. Hidden among them are a duplicate of order 1002, a missing customer id, the amount "abc", a negative amount, a lowercase "usd", a currency "TRY" that the rules do not yet allow, and a timestamp "not-a-date".

Bronze accepts all ten. That is the point: bronze is your replay source and audit trail.

Silver: type, check, quarantine, deduplicate

Step 1: parse with safe casts

Use casts that return null instead of failing, so one bad value cannot stop the whole batch:

CREATE OR REPLACE TABLE stg AS
SELECT ingest_id,
       payload->>'order_id'                          AS order_id_raw,
       TRY_CAST(payload->>'order_id' AS BIGINT)       AS order_id,
       payload->>'customer_id'                       AS customer_id,
       TRY_CAST(payload->>'amount' AS DECIMAL(12,2))  AS amount,
       upper(payload->>'currency')                   AS currency,
       TRY_CAST(payload->>'order_ts' AS TIMESTAMPTZ)  AS order_ts
FROM bronze_orders;

Note the small cleaning step, upper(currency), which rescues "usd". Normalising is part of silver's job; rejecting is a last resort.

Step 2: name every rule

Instead of one big WHERE clause, evaluate each rule separately and keep the names of the ones that fail:

CREATE OR REPLACE TABLE checked AS
SELECT *,
  list_filter([
    CASE WHEN order_id IS NULL    THEN 'order_id_not_integer' END,
    CASE WHEN customer_id IS NULL THEN 'customer_id_missing'  END,
    CASE WHEN amount IS NULL      THEN 'amount_not_numeric'   END,
    CASE WHEN amount < 0          THEN 'amount_negative'      END,
    CASE WHEN currency NOT IN ('EUR','USD','GBP') THEN 'currency_not_allowed' END,
    CASE WHEN order_ts IS NULL    THEN 'order_ts_invalid'     END
  ], lambda x: x IS NOT NULL) AS failed_rules
FROM stg;

Named rules turn "the pipeline dropped some rows" into "five rows failed, one for each of these reasons", which is what a data owner needs to fix the source.

Step 3: route failures to quarantine

CREATE OR REPLACE TABLE quarantine_orders AS
SELECT ingest_id, order_id_raw, failed_rules
FROM checked WHERE len(failed_rules) > 0;
Table 2. Step 3: route failures to quarantine
ingest_id order_id_raw failed_rules
4 1003 customer_id_missing
5 1004 amount_not_numeric
6 1005 amount_negative
9 1008 currency_not_allowed
10 1009 order_ts_invalid

Quarantined rows are not deleted. They wait, with their reasons, until someone fixes the source or the rule.

Step 4: deduplicate to one row per key

CREATE OR REPLACE TABLE silver_orders AS
SELECT order_id, customer_id, amount, currency, order_ts
FROM checked WHERE len(failed_rules) = 0
QUALIFY row_number() OVER (PARTITION BY order_id ORDER BY ingest_id DESC) = 1;

Silver ends with four orders: 1001, 1002 (once, not twice), 1006 (with USD after normalising) and 1007. Ten bronze rows became four silver rows, five quarantined rows and one removed duplicate, and every one of the ten is accounted for.

The quality gate: when to stop the line

Quarantine handles individual bad rows. A gate handles a bad batch. If half of today's file is broken, loading the good half into gold produces numbers that look plausible and are wrong. A gate compares a batch-level metric with a threshold and fails the run.

SELECT CASE
  WHEN 100.0 * count(*) FILTER (WHERE len(failed_rules) > 0) / count(*) > 5
  THEN error('quality gate failed: reject rate above 5%')
END
FROM checked;

Our batch has 10 rows and 5 rejects, a 50 percent reject rate, so the gate raises "quality gate failed: reject rate above 5%" and the run stops before gold is touched.

Table 3. The quality gate: when to stop the line
Gate type Example check Protects against
Reject rate Under 5 percent of rows quarantined A broken upstream export
Volume Row count within 30 percent of the trailing 7-day average Missing or duplicated files
Freshness Latest order_ts within 2 hours of now Stalled ingestion
Schema Expected columns and types present Upstream schema changes
Reconciliation Silver revenue equals source system total within a tolerance Silent logic errors

Choose per table whether a failed gate should block (stop the run) or warn (load and alert). Gold tables that feed finance should block. Exploratory tables can warn. You can explore how thresholds trade completeness against correctness in the medallion pipeline quality simulation.

Track quality over time

A gate looks at one batch. Trends need history. Write one row per run and rule into a small metrics table, for example run_id, table_name, rule, failed_rows and total_rows, using unnest(failed_rules) over the checked rows. A chart of failures per rule per day shows whether a source is getting worse long before a gate trips, and it tells you which rule to discuss with which upstream team. The same table gives auditors evidence that checks ran, which matters as much as the checks themselves.

Gold: business tables from trusted silver

Gold reads only from silver and encodes agreed definitions:

CREATE OR REPLACE TABLE gold_daily_revenue AS
SELECT CAST(order_ts AT TIME ZONE 'UTC' AS DATE) AS order_date,
       currency, count(*) AS orders, sum(amount) AS revenue
FROM silver_orders
GROUP BY ALL ORDER BY ALL;

With the original rules, gold has three rows: 20 November EUR with 2 orders and 200.50, 21 November EUR with 1 order and 42.10, and 21 November USD with 1 order and 300.00. Revenue stays split by currency; converting currencies is a business rule that belongs in gold with an explicit rate table, not hidden in silver.

Reprocessing: fix the rule, replay from bronze

Suppose the business confirms that Turkish lira orders are valid. The rule was wrong, not the data. Because bronze kept every record, the fix is a rule change and a replay:

  1. Change the allowed currency list to ('EUR','USD','GBP','TRY').
  2. Rebuild stg, checked, quarantine_orders and silver_orders from bronze for the affected period.
  3. Rebuild the affected gold partitions.

After the replay, quarantine drops from 5 rows to 4, silver gains order 1008, and gold gains a fourth row: 21 November TRY with 1 order and 19.90. Nothing was re-extracted from the source system.

Replays are safe only when each layer is deterministic (same input, same output) and idempotent (running twice gives the same result as running once). The patterns above qualify: they read from bronze, overwrite their outputs for the period, and deduplicate by key. In SDP, the equivalent operation is spark-pipelines run --full-refresh silver_orders,gold_daily_revenue, which clears and recomputes only those datasets. For incremental tables, rebuild by partition (for example one day at a time) instead of the whole history.

Table 4. Reprocessing: fix the rule, replay from bronze
Replay scope When to use Cost
One partition or day A rule fix that affects recent data Low
Named datasets (full refresh) Logic change in one silver or gold table Medium; recomputes those tables
Whole graph Bronze schema change or many rules changed High; schedule off-peak

What it means in practice

Medallion is not about three folders. It is about three promises and the controls that keep them. Bronze must be complete and immutable, so retention and access on bronze matter more than anywhere else. Silver must be explainable, so every rejected row needs a named reason. Gold must be correct, so gates must be able to stop it from updating.

Table formats make this practical. Delta Lake and Iceberg commits are atomic, so a failed silver step never leaves half-written tables, and time travel lets you compare gold before and after a replay. The site's pages on the bronze layer, silver layer, gold layer and medallion architecture describe each layer in more depth, and data contract validation and schema drift detection cover the checks that belong at the bronze-to-silver boundary.

What to do now

  1. Make bronze append-only. Store raw payloads with source file, offset and ingestion time, and restrict who can delete from it.
  2. Use safe casts in silver. Replace casts that fail with ones that return null, then check the nulls with named rules.
  3. Name every rule. Record failed rule names per row so quarantine explains itself.
  4. Create a quarantine table per silver table. Review it on a schedule and track counts by rule over time.
  5. Add at least one blocking gate before gold. Start with reject rate and volume checks on your most important table.
  6. Deduplicate on business keys. Decide the tie-breaker (latest ingestion, latest source timestamp) and write it down.
  7. Rehearse a replay. Change a rule in a test environment, rebuild one day from bronze and compare gold before and after.
  8. Use dry runs. If you use Spark Declarative Pipelines, run spark-pipelines dry-run in CI to catch analysis and graph errors.

Risks and open questions

Bronze retention limits replay. If bronze is deleted after 30 days, you cannot fix rules for older data; set retention from how far back corrections may reach.

Gates can block important data. A strict threshold on a noisy source stops the business; tune thresholds per table and send warnings before blocking.

Quarantine becomes a graveyard. Without an owner and a review cadence, quarantined rows pile up and nobody fixes the source.

Replays can change published numbers. Rebuilding gold after a rule fix changes history, so tell report owners and keep the previous version available through time travel.

Watch next: how teams adopt the SCD Type 2 Auto CDC flows in Spark 4.3 Declarative Pipelines for silver history tables, and whether open-source pipeline frameworks add first-class quality expectations.

Frequently asked questions

What is the difference between bronze, silver and gold?

Bronze stores raw data exactly as received, silver stores cleaned and validated entities with one row per key, and gold stores aggregated or business-ready tables. Each layer reads only from the one below it.

Should bad records be dropped or quarantined?

Quarantine them with the names of the rules they failed. Dropping hides problems and makes reconciliation impossible, while a quarantine table lets owners fix the source and lets you replay the rows once fixed.

What is a quality gate?

It is a batch-level check, such as reject rate, row volume or freshness, that stops or flags a run when a threshold is crossed. It protects gold tables from being updated with a broken batch.

How do I reprocess data after fixing a rule?

Change the rule, then rebuild silver and gold for the affected period from bronze. In Spark Declarative Pipelines, --full-refresh with dataset names clears and recomputes only those datasets.

Do I always need three layers?

No. Small or simple sources sometimes go straight from a raw landing table to a gold view. The three-layer pattern earns its keep when data is messy, has many consumers or needs replays and audits.

Summary

The medallion architecture works when each layer keeps a clear promise: bronze is complete and unchanged, silver is typed, validated and deduplicated with named rules and a quarantine table, and gold is built only from trusted silver behind quality gates. In our runnable example, ten raw rows produced four silver orders, five quarantined rows with reasons and one removed duplicate; a 5 percent reject-rate gate stopped the run; and after a rule fix, a replay from bronze added the missing order to gold without touching the source. Spark 4.3.0, released on 30 October 2026, adds SCD Type 2 Auto CDC to Declarative Pipelines, and the same full-refresh and dry-run controls make these replays routine.

Sources

Cite this article

Kelahmet, Ö. C. (2026, November 23). Medallion architecture in practice: bronze, silver and gold with quality gates and replay. Özer Cem KELAHMET. https://www.ozercemkelahmet.com/articles/medallion-architecture-quality-gates-reprocessing

BibTeX
@online{kelahmet2026medallion,
  author = {Kelahmet, {\"O}zer Cem},
  title  = {{Medallion architecture in practice: bronze, silver and gold with quality gates and replay}},
  year   = {2026},
  month  = {nov},
  url    = {https://www.ozercemkelahmet.com/articles/medallion-architecture-quality-gates-reprocessing}
}
Version historyfirst version
  1. Published

Factual corrections are listed here with what changed. Wording and formatting edits are not listed.

Last updated Nov 23, 2026
Type to search.
    ↑↓ navigate↵ open