Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
Databricks · Databricks Data Engineer Professional

AUTO CDC and slowly changing dimensions

Databricks Data Engineer Professional · Lesson 5 of 21 · 39:38

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the Databricks Certified Data Engineer Professional exam. In this lesson: change data capture with AUTO CDC in Lakeflow pipelines, slowly changing dimensions type 1 and type 2, ordering out-of-order changes and applying deletes, and the targets and formats AUTO CDC supports. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Restaurants that change

Quayside Eats copies its restaurants table from an operational database, and receives every insert, update, and delete as a change feed. Finance needs the current address of each restaurant, while the commission team needs the rate that applied on any past date, and changes sometimes arrive out of order. This lesson covers AUTO CDC in Lakeflow pipelines, with slowly changing dimensions of type 1 and type 2.

Change data and AUTO CDC

Change data capture, or CDC, turns every insert, update, and delete in a source into a stream of change records, each with a key, an operation, and a sequence value. Applying those changes by hand means a merge in foreachBatch, with logic for repeated rows, ordering, and deletes, which is easy to get wrong. AUTO CDC, formerly apply changes, with the same syntax, does it declaratively in a Lakeflow pipeline: you create a streaming table, then a flow that names the source, the keys, and the sequencing column. It handles out of order events, and stores the target as a slowly changing dimension of type 1 or type 2. And when the source offers no change feed, only periodic snapshots, AUTO CDC from snapshot compares the snapshots to find the changes.

Type 1 and type 2

Stored as SCD type 1, the target keeps only the latest version of each key: an update overwrites the row, and a delete removes it, so there is no history. Stored as SCD type 2, every change to a key adds a new row, and two columns, start at and end at, show when each version was valid. The current version is the row whose end at is null, and a delete closes the current version instead of erasing the history. By default, a change to any column creates a new version, but track history on, with a column list or with all columns except some, limits the history to the columns that matter. Changes to the other columns then update the current version in place. In Python, the same flow is create_auto_cdc_flow, with stored_as_scd_type set to 1 or 2.

Ordering and deletes

The sequence by column orders the changes for each key, so the latest event wins, even when it arrives first. In type 1, an older change that arrives after a newer one is ignored, and in type 2, it lands in the right place in the history. When two changes share a timestamp, sequence by can take a struct of several columns, like the timestamp and a change number, to break the tie. Apply as delete when gives the condition that marks a delete, and the columns clause, with except, keeps helper columns like the operation and the sequence out of the target. To use AUTO CDC, the pipeline must run on serverless compute, or on the Pro or Advanced level of Lakeflow pipelines.

Targets and formats

AUTO CDC writes to a streaming table, which is a Delta table by default, and it runs incrementally: each update only processes the new change records. To load an existing table first, a once flow can backfill it, and the change feed then continues from there. When other engines must read the result as Apache Iceberg, streaming tables and materialized views can be exposed to Iceberg readers through Unity Catalog, and materialized views can also be created with using Iceberg, which is in preview. External Iceberg readers can read these tables, but they cannot write to them. And for databases like SQL Server, Lakeflow Connect applies type 1 or type 2 for you, as lesson eight shows.

Recap

Let's recap. AUTO CDC, formerly apply changes, applies a change feed to a streaming table, with keys, a sequence by column, and a delete condition. SCD type 1 keeps only the latest version, while SCD type 2 adds a row per change, with start and end columns, and track history on limits which columns create versions. Sequence by handles out of order events, and a struct breaks ties. Without a change feed, AUTO CDC from snapshot compares snapshots. And targets are Delta streaming tables, which Iceberg readers can also read through Unity Catalog.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. A source system cannot produce a change feed: every night, it exports a full copy of its restaurants table. The team wants a type 2 history of what changed between copies. What should the data engineer use?

    • AUTO CDC on the export files
    • A materialized view over the latest copy
    • A streaming table that appends each copy
    • AUTO CDC FROM SNAPSHOT
    Show the answer

    AUTO CDC FROM SNAPSHOT

    AUTO CDC from snapshot compares each new copy with the previous one, and stores the changes as type 2 history. “AUTO CDC on the export files” needs a change feed, with an operation and a sequence for each change, which the source cannot produce. “A materialized view over the latest copy” would only show the latest copy, without any history. And “A streaming table that appends each copy” would append full copies again and again, without working out what changed.

  2. In a type 2 table of restaurants, the phone number changes often. The team does not want a new version for each phone change, only for commission and address changes. What should the flow add?

    • TRACK HISTORY ON * EXCEPT (phone)
    • COLUMNS * EXCEPT (phone)
    • STORED AS SCD TYPE 1
    • APPLY AS DELETE WHEN phone IS NULL
    Show the answer

    TRACK HISTORY ON * EXCEPT (phone)

    Track history on, with all columns except the phone, creates versions only for the other columns, and updates the phone in place. “COLUMNS * EXCEPT (phone)” would drop the phone column from the target entirely. “STORED AS SCD TYPE 1” would drop all history, including the commission changes. And “APPLY AS DELETE WHEN phone IS NULL” would treat rows without a phone number as deletes.

  3. Two change records for the same restaurant carry the same timestamp, and the target sometimes keeps the wrong one. Each record also has an increasing change number. What should the data engineer change?

    • Switch the target to SCD type 1
    • Add the change number to the keys
    • SEQUENCE BY STRUCT(change_ts, change_id)
    • Run the pipeline in continuous mode
    Show the answer

    SEQUENCE BY STRUCT(change_ts, change_id)

    A struct sequences by the timestamp first, and breaks ties with the change number. “Switch the target to SCD type 1” would still pick between the two records unpredictably, and lose the history. “Add the change number to the keys” would make each change a separate key, so the table would no longer hold one restaurant per key. And “Run the pipeline in continuous mode” would change when the pipeline runs, not how it orders the changes.