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

LayerWhat runsWhat it catchesRough time
1. StaticParse every SQL file, load every DAG, lint, check for cycles and missing referencesSyntax errors, broken imports, a task reading a table that no longer existsUnder 1 minute
2. UnitTransform logic on hand-written fixture rows with expected outputsWrong dedupe or join logic, mishandled nulls and edge cases1 to 2 minutes
3. IntegrationBuild changed tables in a CI schema from 1 recent day of prod inputs, then run the quality checks prod runsRow explosions, failed uniqueness, nulls in required columns3 to 10 minutes
4. Data diffCompare the CI output with prod output for the same daySilent changes: rows gained or lost, amounts that moved1 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.

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?

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.