Skip to content

How we designed a release gate for Databricks data quality

Ihor SeleznovUpdated 6 min readVoices

A closed amber inspection gate holds back a new batch of data while previously approved blue data remains available.

Before we published this on 19 October, one case stood out in the local run of our release gate for Databricks data. We injected a duplicate order ID on purpose into a four-order candidate release, and it left the row count and the 100,000-cent total exactly right. Only the uniqueness rule stopped it. We designed the gate because a failed data quality check in Databricks doesn't keep bad data out of the reports and applications people rely on. The check fails, and the rest of the pipeline can carry on and publish.

For a business running reports on Databricks, that's how a duplicate order lands in a revenue total the morning after every check said something was wrong. With the gate in front of them, reports and applications keep showing the last approved data until a new batch passes every critical check, and the bad batch is held back. It costs two job tasks and one frozen copy of each batch.

The run was a local model of the gate on SQLite, with six cases in all, and nothing in it ran on Databricks. By a release we mean making new data available to a reporting table or application. How much a failed check stops depends on where it fails, and that's where the design starts.

A failed expectation has a scope

Lakeflow expectations offer three actions. warn retains invalid rows and records metrics, drop removes them, and fail stops the offending flow. We'd choose the action from the data contract. Dropping an optional event may be acceptable; dropping an order can leave a financial total incomplete.

In triggered mode, a failed expectation rolls back that flow's update while other flows can continue independently. Continuous mode also stops dependent flows. Neither behavior turns a separate validation table into a general release gate. See expectation behavior.

Databricks warns that reading a validation table does not make downstream datasets wait for its result. Its recommended pattern puts validation and downstream processing in separate pipelines, connected through job tasks. See validation tables and pipeline control flow.

Separate pipelines, connected through job tasks

Validation

Downstream processing

Reading a validation table

Validation table

Downstream datasets do not wait for its result

Reading a validation table does not make downstream datasets wait for its result. The recommended pattern puts validation and downstream processing in separate pipelines, connected through job tasks.

Define the blocking rules

Our gate runs on four synthetic orders totaling 100,000 cents, with an independent source manifest that supplies the expected count and total.

Contract Injected defect
IDs are required and unique Replace an ID with an existing ID
Amounts are positive and at most 100,000 cents Set an amount to NULL
Row count matches the manifest Remove an order
Total matches the manifest Change an amount

Every violation blocks publication. Count and total reconciliation fit this example because the transformation preserves orders, while filtering and aggregation need different expectations. These checks cannot prove every field is correct, because matching counts don't prove identity and equal totals can hide offsetting errors.

Aggregate checks belong in a validation dataset. This Lakeflow SQL rejects duplicate or missing IDs.

CREATE OR REFRESH MATERIALIZED VIEW release_checks (
  CONSTRAINT unique_required_ids EXPECT (
    actual_rows = distinct_ids
  ) ON VIOLATION FAIL UPDATE
) AS
SELECT COUNT(*) AS actual_rows,
       COUNT(DISTINCT order_id) AS distinct_ids
FROM dq_gate_demo.staging.orders_r101;

COUNT(DISTINCT order_id) excludes NULL, so missing IDs also break equality. An empty batch passes this rule; count and total checks against the source manifest reject it.

Connect validation to publication

Two pipeline tasks validate and publish the same frozen candidate. A failed validation leaves the previous release available.

For a triggered or scheduled job, the gate is two separate pipeline tasks.

  1. Validate reads the frozen candidate and fails the update on any blocking violation.

  2. Publish depends directly on Validate, sets Run if to All succeeded, and reads the same candidate.

With that setting, if validation fails, publication is marked Upstream failed. Validation must actually execute and succeed. Excluded dependencies receive special handling, so skipping validation is not a pass. See task dependencies. This pattern requires validation to complete; continuous jobs run pipelines differently.

Task order does not freeze data. Materialize a candidate under a release-specific name, make both tasks read it, and prevent changes until publication completes, because a release-specific name alone does not enforce immutability.

Keep consumers on the previous release until validation passes. Restrict publication to the gated workflow, because another schedule or writer can bypass it. Serialize releases so an older approved candidate cannot overwrite a newer one.

Prove that failure prevents publication

Local SQLite demonstration: the clean candidate publishes R101; a duplicate ID blocks publication and keeps R100 unchanged.

Our companion demonstration runs locally on SQLite, and it doesn't execute Databricks or Lakeflow. Each scenario starts with R100, which holds two orders totaling 90,000 cents.

The clean candidate publishes R101 with four orders totaling 100,000 cents. Replacing one ID with a duplicate leaves both count and total unchanged, but fails uniqueness, so publication doesn't run. The demonstration asserts that R100's exact rows remain unchanged.

Missing-order, NULL-amount and empty-batch cases also block publication, while another case changes the source after validation and confirms that publication reads the frozen candidate.

We'd repeat the clean and duplicate cases in a Databricks test workspace before relying on the gate, recording the candidate identity, rule version, job run ID, named validation error, publication task state, and consumer rows before and after. A permissions failure proves nothing about the quality rule. Failed fail updates do not record expectation metrics; inspect failure details.

The gate is proven when valid data advances, a critical defect prevents publication from running, and consumers keep the previous approved data. Which defects count as critical is the next question, and our kill matrix of twelve injected defects is how we'd answer it before the gate goes live. The same failure path matters for code as for data: a notebook test that fails has to fail the CI check too. Both sit with the freshness, volume and schema checks in how we run data engineering on Databricks, and with the data and AI governance that decides who may publish at all.

Frequently asked questions

How do we take back a release that turns out to be wrong after publication?

Point consumers back at the previous approved release. Because every candidate is materialized under its own name and releases are serialized, the last good one is still there to switch to, and the bad candidate stays put for whoever investigates it. For a table published in place, Delta's RESTORE TABLE ... TO VERSION AS OF returns it to an earlier version, as long as the table still keeps both the transaction log and the data files for that version, which means setting its retention to cover the rollback window.

Which checks should block a release, and which should only warn?

Block on anything that changes identity or a financial total, such as duplicate or missing IDs, a lost order or a total that disagrees with the source manifest. An optional field arriving empty is a warn, because holding a whole release for it costs more than the gap. We'd write the list down with whoever owns the report, since they decide what a wrong number costs.

Does the gate make every pipeline run slower?

It adds one task to each run, the validation that reads the frozen candidate for its counts, totals and uniqueness checks, and publication itself is unchanged. We haven't timed that task on Databricks, so how long it takes depends on the batch. What a team does give up is publishing while validation is still running, and that's the point of the gate.