CertSafari
    Databricks Certified Data Engineer Professional - October 9 onwards· Lessons

    Domain 2 · Lesson 14/45

    Incremental AUTO CDC flows into Delta and Iceberg-readable tables

    Configure incremental CDC pipelines using Lakeflow Pipelines with Delta or Iceberg as the target table format.

    14 min read
    2.4% of exam
    9 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Configure an AUTO CDC flow so that out-of-order events, deletes and history land correctly in a streaming table target
    • Use a Delta table's change data feed as the streaming source of an AUTO CDC flow, and read the change feed of an AUTO CDC target downstream
    • Make a CDC target readable by Iceberg clients with UniForm Iceberg V3 properties, and know the limits that come with it

    Key concept

    Sequenced upsert into a streaming table — An AUTO CDC flow reads a stream of change events and, for each key, upserts the event into a streaming table unless a clause tells it to delete. The SEQUENCE BY column decides which event for a key wins, so the result is correct even when events arrive out of order.

    1.The clauses that make a CDC flow correct

    A streaming table on its own only appends rows. When the source carries updates and deletes, such as a bronze table of events from Debezium or a Delta table's change feed, you put an AUTO CDC flow in front of the streaming table so those events change rows that already exist. The AUTO CDC API (formerly APPLY CHANGES) does the merge for you: it upserts by key and stores the result as SCD Type 1 or Type 2. Getting it right comes down to a few clauses. CDC flows need serverless Lakeflow pipelines or the Pro or Advanced edition.

    SEQUENCE BY is the ordering contract. The clause is required. For each key, it tells the flow which event is newest. When a network retry delivers an updated_at of 09:00 after an event from 09:05, the flow compares the sequence values and keeps the 09:05 state. A plain MERGE would let the later arrival overwrite the newer state. To break ties, pass a STRUCT, for example SEQUENCE BY STRUCT(timestamp_col, id_col), which orders by the first field and then by the second. Other clauses don't fix ordering. IGNORE NULL UPDATES only means that columns with a null value in an incoming event keep their existing value in the target. Switching to SCD Type 2 changes what is stored, not which event wins.

    Deletes only happen when you ask for them. Every INSERT and UPDATE event is an upsert, and so is anything else unless APPLY AS DELETE WHEN op = 'DELETE' marks it as a delete. A deleted key doesn't disappear from storage right away. The flow keeps it as a tombstone so that a late event with an older sequence value can't bring the key back. A view in the metastore filters the tombstones out. The tombstone retention defaults to two days and is set with the pipelines.cdc.tombstoneGCThresholdInSeconds table property. Set it longer than the worst delay you expect between an event and the pipeline run that processes it. APPLY AS TRUNCATE WHEN is a different tool: it clears the entire target, and it works only with SCD Type 1.

    An SCD Type 2 AUTO CDC flow: required keys and sequencing, explicit delete handling, and metadata columns dropped from the targetsql
    -- Create a streaming table, then use AUTO CDC to populate it:
    CREATE OR REFRESH STREAMING TABLE target;
    
    CREATE FLOW flow
    AS AUTO CDC INTO
      target
    FROM stream(cdc_data.users)
      KEYS (userId)
      APPLY AS DELETE WHEN operation = "DELETE"
      SEQUENCE BY sequenceNum
      COLUMNS * EXCEPT (operation, sequenceNum)
      STORED AS SCD TYPE 2
      TRACK HISTORY ON * EXCEPT (city);

    The target has to be a streaming table that you declare before the flow. With STORED AS SCD TYPE 2, each version of a key becomes its own row, and its validity window is in the __START_AT and __END_AT columns. The current version is the one with a null __END_AT. A user whose city changes from Monterrey to Carmel at sequence 1 ends up with one closed row (__START_AT 0, __END_AT 1) and one current row (__START_AT 1, __END_AT NULL). If you declare the target schema yourself, these two columns must have the same data type as the sequencing column. The target also keeps every source column, including op and the sequencing column, unless COLUMNS * EXCEPT (...) drops them. That clause only shapes the target schema. It doesn't change how events are applied.

    In SCD Type 2, a delete closes the active row instead of adding one. When an event matches the APPLY AS DELETE WHEN condition, the flow sets __END_AT on the key's current version to the event's sequence value, and that row stays in the table. A user deleted at sequence 6 keeps their earlier version with __END_AT 6, and no row for that key has a null __END_AT any more. SCD Type 2 keeps complete history. The two-day tombstone setting above governs how long the flow can still resolve late-arriving deletes, not how long history is retained.

    Checkpoint 1 of 6· Fill the gap

    Network retries mean that events for a user can arrive out of order, so an UPDATE with sequenceNum 5 can land after the one with sequenceNum 6. Which clause completes this flow so that it requires an ordering column and keeps the newest state for each userId?

    -- Create a streaming table, then use AUTO CDC to populate it:
    CREATE OR REFRESH STREAMING TABLE target;
    
    CREATE FLOW flow
    AS AUTO CDC INTO
      target
    FROM stream(cdc_data.users)
      KEYS (userId)
      APPLY AS DELETE WHEN operation = "DELETE"
       ?  sequenceNum
      COLUMNS * EXCEPT (operation, sequenceNum)
      STORED AS SCD TYPE 2
      TRACK HISTORY ON * EXCEPT (city);

    Checkpoint 2 of 6· Exam question

    A bronze streaming table receives CDC events with columns customer_id, op, updated_at, and other attributes. Events sometimes arrive out of order because of network retries. An engineer defines: CREATE OR REFRESH STREAMING TABLE dim_customer; CREATE FLOW customer_cdc AS AUTO CDC INTO dim_customer FROM stream(bronze_customer_changes) KEYS (customer_id) STORED AS SCD TYPE 1; During testing, an update carrying an earlier updated_at value overwrites a row that had already been updated with a later updated_at. Which change fixes this?

    Checkpoint 3 of 6· Exam question

    A streaming table target receives events with an op column set to 'INSERT', 'UPDATE', or 'DELETE'. After deploying: CREATE OR REFRESH STREAMING TABLE orders_silver; CREATE FLOW orders_cdc AS AUTO CDC INTO orders_silver FROM stream(bronze_orders_changes) KEYS (order_id) SEQUENCE BY event_ts STORED AS SCD TYPE 1; rows marked as deletes in the source still appear in orders_silver after the flow runs. Which addition resolves this?

    Checkpoint 4 of 6· Exam question

    A team replaces a hand-written MERGE INTO upsert job with: CREATE OR REFRESH STREAMING TABLE dim_customer; CREATE FLOW customer_cdc AS AUTO CDC INTO dim_customer FROM stream(bronze_customer_changes) KEYS (customer_id) APPLY AS DELETE WHEN op = 'DELETE' SEQUENCE BY change_version STORED AS SCD TYPE 2; Which statements correctly describe the resulting dim_customer table? (Select all that apply)(Select 3)

    0 of 3 selected

    Sources1234

    2.Using a Delta change data feed as the source

    The source of an AUTO CDC flow must be a streaming read, and it is safest when that read is append-only. If a plain streaming read of a Delta table hits a commit that updated or deleted rows, it throws an error. A Change Data Feed (CDF) solves this. Read the upstream table with readChangeFeed and each update or delete arrives as a new row describing the change. That gives AUTO CDC an incremental, append-shaped stream to sequence and apply.

    A streaming read of a Delta table's change data feed, which can serve as the AUTO CDC sourcepython
    (spark.readStream
      .option("readChangeFeed", "true")
      .table("<table_name>")
    )
    How the change feed's metadata columns map to AUTO CDC clauses
    Change feed columnWhat it holdsRole in the AUTO CDC flow
    _change_typeinsert, update_preimage, update_postimage, deleteDrives APPLY AS DELETE WHEN for delete rows. Filter out update_preimage, because it is the value before the update
    _commit_versionThe Delta table version that contains the changeA natural SEQUENCE BY column, because it orders changes per commit
    _commit_timestampWhen the commit was createdAn alternative ordering column

    The first run is the one people get wrong. When a change feed stream starts, it returns the latest snapshot of the table as INSERT records and then returns later changes. For a new target that is what you want: an initial load followed by incremental changes. If the target already holds the state up to some version, specify a starting version so the source table isn't processed again as INSERT events. Exclude the metadata columns with COLUMNS * EXCEPT so they don't end up in the target.

    An AUTO CDC target can be the source for the next table. In Databricks Runtime 15.2 and above, you can read a change data feed from a streaming table that is the target of AUTO CDC, provided the table is published to Unity Catalog. A pipeline that reads it must also run 15.2 or above. A normal update produces update_preimage and update_postimage rows. A change to a primary key is different: it shows up as an insert plus a delete, because the feed sees the old key value disappear and a new one appear. In an SCD Type 2 target the primary key is the flow's key plus coalesce(__START_AT, __END_AT), which uses __START_AT when it is set and __END_AT when __START_AT is null, as in an initial record. A back-dated start sequence is a late event with an older sequence value than the version's current start, so the version's __START_AT moves earlier. A row that began at 5 and is corrected to begin at 3 changes its key from (key, 5) to (key, 3), and the feed reports an insert for the new key value and a delete for the old one.

    Checkpoint 5 of 6· Check yourself

    An AUTO CDC flow reads a silver Delta table with a plain streaming read. Another job runs MERGE statements that update and delete rows in that silver table, and the pipeline's next run fails on the source read. What change gives the flow an incremental source it can sequence and apply?

    Sources2156

    3.Making the CDC target readable as Iceberg

    AUTO CDC writes into a streaming table, so to open a CDC target to Iceberg engines you enable UniForm Iceberg reads on that Delta streaming table. You don't change its storage format. The table needs external metadata access plus the UniForm Iceberg V3 properties. USING ICEBERG is a shortcut that exists only for materialized views, which can be managed Iceberg (Public Preview). Iceberg readers can read those views but can't write to them.

    Table properties that make a pipeline streaming table readable by Iceberg clients
    PropertyPurpose
    'pipelines.externalMetadata.enabled' = 'true'Enables external access. As a table property it overrides the pipeline configuration
    'delta.columnMapping.mode' = 'name'Column mapping, which Iceberg requires
    'delta.enableRowTracking' = 'true'Row tracking for Iceberg reads
    'delta.universalFormat.enabledFormats' = 'iceberg'Turns on Iceberg reads
    'delta.enableIcebergCompatV3' = 'true'Uses Iceberg V3. Streaming tables cannot use IcebergCompatV2

    The properties take effect on the next pipeline run. Run a triggered pipeline once. Stop and restart a continuous one. The external metadata flag can also be set for every dataset at once with pipelines.externalMetadata.enabled in the pipeline configuration, and a table-level setting wins when both are set.

    Iceberg reads come with limits that affect CDC designs:

    • Iceberg clients can only read. Every write still goes through the pipeline.
    • Legacy change data feed works for Delta clients, but Iceberg doesn't support it. A downstream consumer that needs the CDC target's change feed must read it as Delta.
    • Delta and Iceberg version numbers and timestamps don't line up, so look up converted_delta_version to see which Delta version an Iceberg snapshot reflects.
    • Iceberg metadata is generated automatically only when the table is accessed by name, not by path. Delta tables with Iceberg reads enabled don't support VOID types.

    If metadata generation is interrupted, MSCK REPAIR TABLE <table-name> SYNC METADATA regenerates it for the latest version.

    Checkpoint 6 of 6· Check yourself

    After Iceberg reads are turned on for an SCD Type 2 AUTO CDC target, an analytics team using an external Iceberg engine asks for two things: a way to fix bad rows and a way to pick up incremental changes. Which design works?

    Sources789

    Sources

    (9)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “To use the CDC APIs, your pipeline must be configured to use serverless Lakeflow pipelines or the Lakeflow pipelines Pro or Advanced editions.”
      ↩︎ The clauses that make a CDC flow correct
      “The table preserves complete history. User 123 has two versions (ended at sequence 6 when deleted).”
      ↩︎ The clauses that make a CDC flow correct
      “Records with __END_AT = null are currently active.”
      ↩︎ The clauses that make a CDC flow correct
      “AUTO CDC processes changes from a change data feed (CDF).”
      ↩︎ Using a Delta change data feed as the source
    2. 2.
      “The pipeline processing uses this sequencing to handle change events that arrive out of order.”
      ↩︎ The clauses that make a CDC flow correct
      “columns with a null value retain their existing values in the target”
      ↩︎ The clauses that make a CDC flow correct
      “The APPLY AS TRUNCATE WHEN clause is supported only for SCD type 1.”
      ↩︎ The clauses that make a CDC flow correct
      “You must declare a target streaming table to apply the changes into.”
      ↩︎ The clauses that make a CDC flow correct
      “The default is to include all columns in the target table when the COLUMNS clause is not specified.”
      ↩︎ The clauses that make a CDC flow correct
      “If the read encounters a change or deletion to an existing record, an error is thrown.”
      ↩︎ Using a Delta change data feed as the source
      “The default behavior for INSERT and UPDATE events is to upsert CDC events from the source”
      ↩︎ Key concept
      “The pipeline processing uses this sequencing to handle change events that arrive out of order.”
      ↩︎ Exam trap 1
      “Because this clause triggers a full truncate of the target table, it should be used only for specific use cases requiring this functionality.”
      ↩︎ Exam trap 2
      “Handling for DELETE events can be specified with the APPLY AS DELETE WHEN condition.”
      ↩︎ Prediction
    3. 3.
      “The retention interval defaults to two days, and can be configured with the pipelines.cdc.tombstoneGCThresholdInSeconds table property.”
      ↩︎ The clauses that make a CDC flow correct
    4. 4.
      “closes out the current version when a delete event arrives.”
      ↩︎ The clauses that make a CDC flow correct
    5. 5.
      “change data feed returns the latest snapshot of the table as INSERT records and then returns future changes as change data”
      ↩︎ Using a Delta change data feed as the source
      “specify a starting version to avoid processing the source table state as INSERT events”
      ↩︎ Using a Delta change data feed as the source
      “preimage is the value before the update, postimage is the value after the update.”
      ↩︎ Using a Delta change data feed as the source
    6. 6.
      “you can read a change data feed from a streaming table that is the target of AUTO CDC or AUTO CDC FROM SNAPSHOT queries”
      ↩︎ Using a Delta change data feed as the source
      “When changes include updates to primary keys, the _change_type metadata fields are set to insert and delete events.”
      ↩︎ Using a Delta change data feed as the source
      “when the __start_at field changes to reflect an earlier start sequence value”
      ↩︎ Using a Delta change data feed as the source
      “This uses __START_AT when available, and __END_AT when __START_AT is null (for example, the initial record).”
      ↩︎ Using a Delta change data feed as the source
      “target of AUTO CDC or AUTO CDC FROM SNAPSHOT queries in the same way that you read a change data feed from other Delta tables”
      ↩︎ Checkpoint
    7. 7.
      “add the following UniForm Iceberg V3 properties in addition to the external metadata property”
      ↩︎ Making the CDC target readable as Iceberg
      “For materialized views, you can use the equivalent USING ICEBERG syntax instead.”
      ↩︎ Making the CDC target readable as Iceberg
      “Triggered pipelines: Run the pipeline once. Continuous pipelines: Stop and restart the pipeline.”
      ↩︎ Making the CDC target readable as Iceberg
    8. 8.
      “Managed Iceberg materialized views are in Public Preview.”
      ↩︎ Making the CDC target readable as Iceberg
    9. 9.
      “Iceberg reads can't be enabled on materialized views or streaming tables using IcebergCompatV2.”
      ↩︎ Making the CDC target readable as Iceberg
      “Legacy change data feed works for Delta clients when Iceberg reads are enabled but doesn't have support in Iceberg.”
      ↩︎ Making the CDC target readable as Iceberg
      “Delta Lake table versions aren't guaranteed to align with Iceberg versions by either the commit timestamp or the version ID.”
      ↩︎ Making the CDC target readable as Iceberg
      “The Delta Lake table must be accessed by name (not path) to automatically trigger Iceberg metadata generation.”
      ↩︎ Making the CDC target readable as Iceberg
      “Iceberg client support is read-only. Writes are not supported.”
      ↩︎ Exam trap 3

    Continue to part 2 of 2

    AUTO CDC FROM SNAPSHOT: change data capture from full snapshots

    Spotted a mistake, or was something unclear? Tell us.