Lakehouse Data Quality Checks for Bronze, Silver and Gold: Executable Promotion Gates for a Retail Orders Pipeline
Build lakehouse data quality gates for schema drift, duplicate events, late CDC, null keys and referential integrity, with quarantine and replay checks.
Author: jackey.ye | Last updated: 2026-11-23
Bronze, silver and gold become gates when every layer boundary carries a named check, a threshold, a pass/fail outcome and a quarantine path — and promotion is blocked until the gate passes. This article specifies those gates for a retail orders pipeline: order events plus CDC from an orders source. SQL blocks are labeled Portable ANSI or dialect-specific.
Why Gates Beat Zones: The Difference From a Medallion Architecture Overview
A medallion overview explains what the layers are and why layering helps; it answers an architectural question. This article assumes that answer and asks a narrower, operational one: what must be true before a batch or micro-batch is allowed to move from one layer to the next, and who can prove it afterwards.
The difference is enforcement. A zone describes where data sits. A gate decides whether data may move, and leaves a record of that decision. Each gate needs a check name, a scope (which table, batch and key range), a threshold, a pass action, a fail action, an owner, and an evidence record written to a control table. Remove the evidence record and the gate is only a comment in a runbook — nothing downstream can read it, so nothing downstream is actually blocked.
If you need the architectural background first — what bronze, silver and gold are, and how layering reduces duplicated work — read the medallion architecture overview on the site before continuing. The rest of this article takes that structure as given and works only on the promotion mechanics.
The Gate Contract: What Every Promotion Check Must Record
Every check writes one row per batch per check to a control table, and that table — not a dashboard, not a chat message — is what promotion reads. The minimum columns are: gate_id, layer_from, layer_to, run_id, check_name, metric_value, threshold, status (pass / fail / quarantined), evaluated_at, and the scope actually evaluated — the batch watermark or the CDC sequence range.
Recording the evaluated scope is the part teams skip and later regret. A pass on order_events for sequence range 1000–2000 says nothing about 2000–3000, and a freshness pass at 09:00 says nothing about 11:00. Without the range in the row, a stale pass can be mistaken for a current one and the gate silently opens.
The downstream job then does one thing before it starts: read the latest status for its input batch and exit non-zero unless every blocking check is pass. That single read is what converts a documented rule into an executable one. The numbered steps below show how to build it in order.
Which Checks Belong at Which Layer
The allocation below is a recommended starting point for a retail orders pipeline, not a universal standard, and the thresholds are illustrative — set yours from your own SLA and source behavior. Two principles drive it: bronze detects and records without blocking on things it cannot control (parents arriving late, duplicates inherent to append-only landing), while silver and gold enforce, because by then the data is expected to be conformed.
Check | Bronze gate | Silver gate | Gold gate | Typical fail action |
|---|---|---|---|---|
Schema drift | Required: new/renamed/dropped columns vs registered schema | Confirm conformed types after cast | Confirm mart columns match contract | Quarantine batch; block promotion |
Duplicate event IDs | Detect, do not block (landing is append-only) | Required: one row per event_id after dedupe | Not applicable (already unique) | Quarantine duplicates; replay after fix |
Late CDC | Record arrival vs event time | Required: lateness within watermark | Flag affected aggregates | Hold aggregate; backfill |
Null keys | Count nulls in order_id/event_id | Required: zero null business keys | Required: zero null join keys | Quarantine rows |
Referential integrity | Not enforced | Required: order→customer, line→order | Required: fact→dimension | Quarantine orphans |
Reconciliation | Row counts landed vs source extract | Counts in vs counts out after dedupe | Sum(order_total) vs source ledger | Block; investigate |
Freshness SLA | Ingestion lag | Transformation lag | Query-ready lag | Alert; mark stale |
Read the columns as a sequence, not a menu. A check that appears at silver usually also ran at bronze in a weaker form; the silver version is the one that blocks.
Check-by-Check SQL: Portable and Dialect-Specific
Each example below is labeled with its portability. Thresholds are placeholders.
Schema drift
Portable ANSI. Compare live columns against a registered expected-columns table:
SELECT c.column_name, c.data_type
FROM information_schema.columns c
WHERE c.table_schema = 'bronze'
AND c.table_name = 'order_events'
AND NOT EXISTS (
SELECT 1 FROM dq.expected_columns e
WHERE e.table_name = 'order_events'
AND e.column_name = c.column_name
AND e.data_type = c.data_type
);
Any returned row is drift; the batch is quarantined and promotion blocked until the contract is updated or the column is mapped.
Dialect-specific (Databricks / Spark). Auto Loader tracks schema in cloudFiles.schemaLocation and controls drift through cloudFiles.schemaEvolutionMode. The documented modes behave differently: addNewColumns (the default when no schema is provided) adds new columns to the schema and then fails the stream with an UnknownFieldException until restart; rescue never evolves the schema and records new columns in the rescued data column instead of failing; failOnNewColumns fails and does not restart until you update the schema or remove the file. Note also that none is the default when you provide a schema, and addNewColumns is not allowed in that case. Choose the mode that matches your gate: failOnNewColumns is the closest to a hard block. See the Auto Loader schema documentation.
Duplicate event IDs
Portable ANSI. Return the offending IDs and their counts:
SELECT event_id, COUNT(*) AS occurrences
FROM bronze.order_events
WHERE ingest_batch_id = :batch_id
GROUP BY event_id
HAVING COUNT(*) > 1;
At bronze this query records duplicates without blocking — landing is append-only and redelivery is expected. At silver the same query must return zero rows after dedupe. Write the dedupe rule down before you implement it: keep the row with the highest CDC sequence, or the latest ingest timestamp, and state the tiebreaker. A rule that changes between runs makes replay non-deterministic.
Late CDC
Portable ANSI. Compare event time to ingest time against the agreed lateness window:
SELECT event_id, event_ts, ingest_ts
FROM bronze.order_events
WHERE ingest_ts > event_ts + INTERVAL '30' MINUTE;
The interval literal form above is widely supported but not universal; some engines want DATEADD, others TIMESTAMPADD, and Spark accepts INTERVAL 30 MINUTES. Treat the arithmetic as portable and the function names as dialect-specific. Rows later than the window are quarantined for ordered replay rather than applied out of order, because applying an older CDC record after a newer one silently reverts a field.
Null keys
Portable ANSI.
SELECT COUNT(*) AS null_key_rows
FROM silver.orders
WHERE order_id IS NULL OR customer_id IS NULL;
Which keys matter changes by layer: event_id and order_id are business keys at bronze and silver; customer_id and product_id become join keys at gold. Null-key rows go to quarantine. Do not substitute a default value — a sentinel key creates a fake parent that passes referential integrity and corrupts the join.
Referential integrity
Portable ANSI. Anti-join with NOT EXISTS:
SELECT l.order_line_id
FROM silver.order_lines l
WHERE NOT EXISTS (
SELECT 1 FROM silver.orders o WHERE o.order_id = l.order_id
);
Bronze does not enforce this, because a line can land before its parent order. Silver enforces within the batch plus a lookback window wide enough to cover expected arrival skew. Gold enforces against conformed dimensions, where a missing parent is a real defect rather than a timing artifact.
Reconciliation
Portable ANSI. Compare the landed aggregate to the source ledger:
SELECT
(SELECT SUM(order_total) FROM gold.fct_orders WHERE order_date = :d) AS mart_total,
(SELECT SUM(order_total) FROM stage.ledger_extract WHERE order_date = :d) AS source_total;
At bronze, reconcile landed row counts to the source extract count. At silver, reconcile counts in to counts out after dedupe and explain every difference. At gold, reconcile amounts. Row counts can match while amounts differ — a duplicated line with a reversed sign nets to the same count — so a count-only check is not a reconciliation.
Freshness SLA
Portable ANSI.
SELECT CURRENT_TIMESTAMP AS checked_at,
MAX(event_ts) AS latest_event,
CURRENT_TIMESTAMP - MAX(event_ts) AS lag
FROM gold.fct_orders;
CURRENT_TIMESTAMP is standard; subtracting timestamps to get an interval is not uniformly supported, and engines differ on whether the result is an interval or a number of seconds. The SLA threshold itself is a business decision recorded in the gate contract, not a technical default. When the gate fails, mark the gold table stale rather than serving it as current — a labeled stale table is safer than a silent one.
Quarantine and Replay: Designing for Idempotency and Audit
A quarantine table is an audit record, not a dead-letter bin. Each row should carry the original payload, the failing check name, the batch and run id, the source offset or CDC sequence, the quarantine timestamp, a status (open / replayed / discarded), and who resolved it and when. Without the source offset you cannot replay in order; without the resolver you cannot answer an audit question six months later.
Replay means re-running the same batch through the same gate after the fix, keyed on a deterministic batch id derived from the source range rather than from wall-clock time. That key is what prevents a second run from double-applying: the target write must be an upsert on that key, not an insert.
Delta Lake's MERGE is the usual mechanism, and its documentation is explicit about two things worth designing around. First, a merge operation can fail if multiple rows of the source dataset match a single target row — so dedupe the source before merging, which is exactly what the silver duplicate gate already produces. Second, when MERGE runs inside foreachBatch in a streaming job, the statement must be idempotent, because a micro-batch can be retried. Both constraints point the same way: dedupe upstream, key the write deterministically, and let the gate re-evaluate on every attempt. See the Delta Lake merge documentation.
Implementation Steps: Building the Gates in Order
Build in this order; each step depends on the artifact the previous one produces. Every step names its expected pass and fail outcome so you can verify it before moving on.
Register the expected schema and column contract. Store expected columns and types in a versioned table keyed by schema version. Pass: a contract row exists for the batch's schema version. Fail: promotion is blocked until the contract is updated or the batch is quarantined.
Create the gate control table. One row per check per batch, with the columns defined earlier. Pass: the table exists and accepts writes from a test run. Fail: no gate can be recorded, so promotion must default to blocked — never to open.
Implement the bronze checks. Schema drift, duplicate detection, null keys and ingestion freshness. Pass: all bronze checks record
passfor a clean batch. Fail: the batch is quarantined and promotion is blocked.Implement the silver checks. Dedupe to one row per
event_id, late-CDC watermark, referential integrity, and counts in versus counts out. Pass: silver checks pass and the dedupe rule is documented in the contract. Fail: offending rows are quarantined and the batch is held.Implement the gold checks. Reconciliation of
SUM(order_total)to the source ledger, fact-to-dimension integrity, and the freshness SLA. Pass: amounts and counts reconcile within the agreed tolerance. Fail: the aggregate is held and marked stale.Wire promotion to gate status. The downstream job reads the latest gate status for its input batch and exits non-zero on fail. Pass: a deliberately failing batch does not reach the next layer. Fail: promotion logic is not enforcing — fix this before proceeding, because every later step assumes it.
Test the fail path deliberately. Inject a duplicate, a null key, a late row and a schema change. Pass: each is caught by the intended gate and quarantined. Fail: a bad row reaches the next layer, which means the gate is incomplete.
Document replay and ownership. Each check has a named owner and a written replay procedure. Pass: a quarantined batch can be replayed and passes on the second run without duplicating rows. Fail: replay double-applies or cannot be traced — fix idempotency before go-live.
Common Failure Modes
These are the mistakes that make gates decorative. Each has a one-line fix.
Zero-tolerance thresholds the source cannot meet. A null-key gate set to zero on a source that legitimately emits nulls produces permanent quarantine. Fix: set the threshold from measured source behavior and review it quarterly.
Gates that log but do not block. A check writes
failand the job proceeds anyway. Fix: make promotion read the status and exit non-zero; test it with a bad batch.Dedupe rules that change between runs. The tiebreaker shifts from ingest time to sequence number mid-incident. Fix: version the rule in the contract and reference the version in the gate row.
Replay that inserts instead of upserting. The second run doubles revenue. Fix: key the write on a deterministic batch id and use an upsert.
Freshness measured from the wrong timestamp. Lag computed from ingest time hides a stalled source. Fix: measure from the event timestamp for source lag and from the write timestamp for pipeline lag, and record which one each gate uses.
Reconciliation by row count only. Counts match while amounts differ. Fix: reconcile amounts at gold, not just rows.
Acceptance Checklist Before You Call the Pipeline Gated
Run this list against the pipeline itself, not the design document. Each item should be answerable with a query result or a link to the control table.
Every layer boundary (bronze→silver, silver→gold) has at least one blocking check, not just an alerting check.
Every check writes a row to the gate control table with metric value, threshold, status and the batch watermark or CDC sequence range it evaluated.
Every failing check routes the offending rows to a quarantine table with the original payload and the failing check name.
Every quarantine table has a documented replay path that re-runs the same batch id through the same gate.
Every replay is idempotent — a second run of the same batch cannot double-apply rows or double-count amounts.
Every check has a named owner and a review cadence for its threshold.
The downstream job exits non-zero on a failed gate rather than logging and continuing.
A deliberately bad batch has been tested and confirmed blocked at each boundary.
FAQ
The five questions below cover the decisions readers most often get wrong: how a zone becomes a gate, which check belongs where, how quarantine and replay stay idempotent, which SQL travels between engines, and how this differs from a medallion overview.
How do I turn bronze/silver/gold boundaries into executable pass/fail gates rather than descriptive zones?
Attach at least one blocking check to each boundary, write its result to a control table, and make the downstream job read that result and refuse to run on fail. A zone becomes a gate when promotion is conditional on a recorded pass.
Which checks belong at each layer for a retail orders pipeline?
Bronze detects schema drift, duplicate event IDs, null keys and ingestion freshness. Silver enforces dedupe, late-CDC watermarks, referential integrity and counts in versus counts out. Gold enforces reconciliation to the source ledger, fact-to-dimension integrity and the freshness SLA.
How should quarantine tables and replay be designed for idempotency and audit?
Store the original payload, failing check, batch id, source offset and status. Replay the same batch through the same gate keyed on a deterministic batch id, and upsert rather than insert so a second run cannot double-apply. Delta's MERGE documentation notes that a merge can fail when multiple source rows match a single target row, so deduplicate before merging.
Which SQL is portable ANSI versus dialect-specific?
GROUP BY with HAVING, NOT EXISTS, IS NULL and SUM/COUNT comparisons are portable. Schema history, Auto Loader schema evolution modes, MERGE and many date and time functions are dialect-specific and should be labeled as such.
How does this differ from a general medallion architecture article?
A medallion overview explains what the layers are. This article assumes that and specifies what must be true, recorded and enforced before data moves between them.
Where This Fits in a Governed Lakehouse
Gate results, quarantine tables and replay logs are themselves governed data. If they live in the same lakehouse as the orders pipeline, in open table formats, an auditor can join a gold aggregate back to the exact check run that admitted it without exporting anything. That is also the argument for avoiding duplicate copies of the pipeline: every additional copy is another place where reconciliation has to be re-proven, a point the data centralization benefits guide develops in detail. Singdata sells a lakehouse platform, so it has a commercial interest in how you evaluate this pattern; the gate design above stands on its own regardless of which engine executes it.
Place these promotion gates in the wider rollout using the Medallion architecture implementation checklist.
For a related implementation check, see the late-arriving dimension and SCD Type 2 guide.