0% complete

Data ingestion and change data capture · Lesson 3 of 3

Change data capture and incremental loads

Apply inserts, updates, and deletes from an evolving source into target tables.

Lesson

Change data capture (CDC) represents source changes rather than requiring a complete table reload for every run. A CDC record may include a business key, change type, source sequence or timestamp, and payload. The target process needs a deterministic rule for ordering multiple changes and applying deletes. If the source provides a transaction sequence, use it to resolve out-of-order arrival rather than trusting ingestion time alone. An incremental pipeline must define its recovery boundary and idempotency behavior. Reprocessing the same change batch should not duplicate effects. Validate key uniqueness, handle late changes, and reconcile target counts or checksums against the source. Practice task: describe how an update followed by a delete should affect a target record when events arrive late. Applying the pattern: Read changes from a known offset or sequence, deduplicate them, apply ordered mutations by business key, and commit progress only after a successful write. Checks and failure modes: Using event arrival time as the only ordering key can apply stale updates after newer changes. Before production, test both a representative input and a boundary case. Confirm the expected row grain, permissions, recovery behavior, and observable output for the task. Record the configuration needed to reproduce the run and compare its result with the agreed data contract. Practice task: Why is a source sequence useful when applying CDC records?

Visual guide

Apply CDC safely

  1. Step 01 Capture

    Read inserts, updates, and deletes.

  2. Step 02 Order

    Resolve duplicate and late changes.

  3. Step 03 Apply

    Merge mutations by business key.

  4. Step 04 Reconcile

    Compare target state with source expectations.

Code examples

Apply ordered changes with MERGE
SQL
MERGE INTO main.crm.silver_customers AS target
USING staged_changes AS source
ON target.customer_id = source.customer_id
WHEN MATCHED AND source.op = 'DELETE' THEN DELETE
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED AND source.op <> 'DELETE' THEN INSERT *;
Expected output
A merge applies updates and deletes by business key; production logic must order duplicate changes first.

Key points

  • Read changes from a known offset or sequence, deduplicate them, apply ordered mutations by business key, and commit progress only after a successful write.
  • Using event arrival time as the only ordering key can apply stale updates after newer changes.
  • Re-run the included practice scenario after changing source data or transformation logic.

Check your understanding

Practice

Why is a source sequence useful when applying CDC records?

Your learning progress

Finish this lesson