CI/CD for Pipelines
Concepts covered: CI/CD for Pipelines
A pipeline change can pass every compile check and still double the rows or drop a filter. It can also change what a column means. CI for pipelines therefore tests the data a change produces as well as the code. The constraint is time: a CI run that takes most of an hour gets skipped, batched into pull requests too large to review, or merged around.
4 layers, cheapest first
| Layer | What runs | What it catches | Rough time |
|---|---|---|---|
| 1. Static | Parse every SQL file, load every DAG, lint, check for cycles and missing references | Syntax errors, broken imports, a task reading a table that no longer exists | Under 1 minute |
| 2. Unit | Transform logic on hand-written fixture rows with expected outputs | Wrong dedupe or join logic, mishandled nulls and edge cases | 1 to 2 minutes |
| 3. Integration | Build changed tables in a CI schema from 1 recent day of prod inputs, then run the quality checks prod runs | Row explosions, failed uniqueness, nulls in required columns | 3 to 10 minutes |
| 4. Data diff | Compare the CI output with prod output for the same day | Silent changes: rows gained or lost, amounts that moved | 1 to 5 minutes |
Each layer catches failures the one before it cannot see. Static checks know nothing about data. Unit tests prove logic on a few hand-written rows, never on 400,000 real ones. An integration build can pass every check and still shift a revenue total; the data diff turns 'the build passed' into 'here is what changes in prod'.
Layer 2: a unit test on fixture rows
def dedupe_latest(rows):
latest = {}
for row in rows:
key = row["order_id"]
if key not in latest or row["updated_at"] > latest[key]["updated_at"]:
latest[key] = row
return sorted(latest.values(), key=lambda r: r["order_id"])
def test_dedupe_keeps_latest_version():
rows = [
{"order_id": 7, "status": "placed", "updated_at": 1},
{"order_id": 7, "status": "shipped", "updated_at": 2},
{"order_id": 9, "status": "placed", "updated_at": 1},
]
result = dedupe_latest(rows)
assert [r["status"] for r in result] == ["shipped", "placed"]
The fixture holds 3 rows built around the case that matters: 2 versions of order 7. A useful next fixture is 2 versions with the same updated_at, which the function resolves by keeping whichever arrived first. The test needs no warehouse and runs in milliseconds, so it runs on every push.
Layer 4: a data diff against prod
SELECT
count_if(c.order_id IS NULL) AS missing_in_ci,
count_if(p.order_id IS NULL) AS new_in_ci,
count_if(p.amount_usd <> c.amount_usd) AS amount_changed
FROM prod.fct_orders AS p
FULL OUTER JOIN ci_pr_412.fct_orders AS c
ON p.order_id = c.order_id
WHERE coalesce(p.order_date, c.order_date) = DATE '2026-10-20'For a pure refactor, every count should be 0. For the lowercase 'usd' fix from the lineage example, diffing 2026-10-20 against the broken prod output should show around 155,000 rows in new_in_ci and nothing missing or changed. That number is the evidence the fix restores the lost payments and touches nothing else.
Slim CI: build only what the change touches
Slim CI uses lineage to choose the build set, which is the tables a pull request modified plus every table downstream of them. Unmodified upstream tables are read from prod instead of rebuilt. In a project of 600 tables, a pull request that edits stg_payments builds 4 tables, stg_payments and fct_orders as well as agg_daily_revenue and customer_ltv; the dashboards and the churn model sit outside the project and stay as they are.
- 52 min
- 6 min
CD: ship the artifact you tested
Deployment promotes the exact code that passed CI to prod on merge, with no rebuild in between. A backfill for changed values runs in forward-lineage order, so each table is rebuilt only from inputs already on the new logic. Order alone leaves a window: until agg_daily_revenue is rebuilt, the refunds dashboard shows new values and the revenue dashboard old ones. Building the affected partitions in a separate schema and swapping them in together closes it.
A pull request that edits fct_orders is described as 'refactor, no behavior change'. Its data diff reports missing_in_ci = 0, new_in_ci = 0 and amount_changed = 18,400. What should the reviewer conclude?
- The change is safe: no rows were gained or lost, and the amount differences are rounding noise to ignore.
- The diff layer is too noisy for refactors, so the reviewer should rely on layers 1 to 3 for this change.
- The refactor changed behavior: 18,400 orders now carry a different amount, and the merge waits until those rows are explained.
- Merge it, then backfill fct_orders so prod matches the new amounts and the diff returns to zero.
About this lesson
This section is part of the Pipeline Operations: Intermediate lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.