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.
-- 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);SEQUENCE BY is the required clause that decides which event for a key is newest, so a late event with sequenceNum 5 cannot overwrite the state from sequenceNum 6. IGNORE NULL UPDATES only keeps existing values where incoming columns are null. TRACK HISTORY ON only chooses which columns create SCD Type 2 history rows.
Source: docs.databricks.comCheckpoint 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?
Correct answer: A — Add SEQUENCE BY updated_at to the flow so it resolves conflicting events for the same key by comparing that timestamp column.
- A.
SEQUENCE BYis the clause that tells the flow which column determines chronological order for a given key, so it can discard or supersede events that arrive late relative to one already applied. Without it, the flow has no way to know that an out-of-order event should not overwrite a newer state. - B.
APPLY AS TRUNCATE WHENclears the whole target table when a truncate signal is present; it has nothing to do with ordering conflicting updates for the same key and would not stop a stale event from being applied. - C. Switching to SCD Type 2 changes how history is stored but does not by itself establish which of two conflicting events is newer — without a sequencing column, a late-arriving stale event can still be treated as the most recent version.
- D.
IGNORE NULL UPDATESaddresses partial-column update events that carry nulls for unchanged fields; it does not address which of two full, out-of-order events should win for a given key.
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?
Correct answer: A — Add APPLY AS DELETE WHEN op = 'DELETE' so the flow removes the matching key from the target table instead of upserting the row.
- A.
APPLY AS DELETE WHENis the clause that tells the flow which incoming rows represent deletions of an existing key, so the flow removes rather than upserts the matching row. Without it, every event — including deletes — is treated as an insert or update. - B. Mapping a per-row delete flag to a table-wide truncate would wipe out every unrelated row in the target on any single delete event, which is both wrong in effect and not what a
DELETEoperation code represents. - C. Dropping the
opcolumn from the output schema only changes what gets written to the target table; it does not tell the flow to interpret rows differently, so deletes would still be merged in as upserts. - D. Switching to SCD Type 2 changes how history is retained, but a delete event is still merged as an upsert unless
APPLY AS DELETE WHENexplicitly identifies which rows represent deletions.
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)
Correct answers: A, B, C — Each version of the customer row is retained as a separate record, with __START_AT and __END_AT columns marking its validity window.; The row representing the customer's current state has its __END_AT column set to null, while every closed-out prior version has a non-null end value.; dim_customer must be declared as a streaming table, since AUTO CDC INTO writes only to streaming table targets, never to materialized views.
- A. SCD Type 2 storage keeps one row per version of a key, and the
__START_AT/__END_ATpair records exactly which period each version was the active state, which is the mechanism that preserves full history. - B. A null
__END_ATis the documented marker for the currently active version of a key; every superseded version instead carries the sequencing value at which it was closed out, which is how a query can filter to only current rows. - C. AUTO CDC INTO applies changes incrementally against a target that supports row-level upserts and history tracking, which is why the target must be declared as a streaming table rather than a materialized view.
- D. AUTO CDC INTO has no built-in time-based pruning of SCD Type 2 history, and
VACUUMretention governs physical file cleanup for time travel, not the logical historical rows a CDC flow writes — this pairing of mechanisms is invented. - E. The sequencing column is not automatically stripped from the output; whether a column appears in the target is controlled by
COLUMNS/except_column_list, so claiming sequencing columns are always dropped misstates how output columns are chosen. - F. For SCD Type 2, a delete event closes out the row that was already active by setting its
__END_AT, using a tombstone mechanism, rather than inserting a fresh row that starts out already ended — that would defeat the purpose of tracking when a version stopped being valid.
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.
(spark.readStream
.option("readChangeFeed", "true")
.table("<table_name>")
)| Change feed column | What it holds | Role in the AUTO CDC flow |
|---|---|---|
| _change_type | insert, update_preimage, update_postimage, delete | Drives APPLY AS DELETE WHEN for delete rows. Filter out update_preimage, because it is the value before the update |
| _commit_version | The Delta table version that contains the change | A natural SEQUENCE BY column, because it orders changes per commit |
| _commit_timestamp | When the commit was created | An 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?
A plain streaming read throws an error when it reaches a commit that changed or deleted existing rows. Reading the change data feed turns each of those changes into a new row, which gives AUTO CDC an append-shaped stream. The other clauses act on how events are applied to the target, so they do nothing about the error in the source read.
“If the read encounters a change or deletion to an existing record, an error is thrown.”Source: docs.databricks.com
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.
| Property | Purpose |
|---|---|
| '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_versionto 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?
Iceberg clients can only read the table, so every write still goes through the pipeline. Iceberg readers can't use the legacy change data feed, so a consumer that needs the CDC target's change feed reads it as Delta, the same way as from any other Delta table.
“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”Source: docs.databricks.com
Sources
(9)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/ldp/cdcOfficial docs
“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.
“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.
“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.
“closes out the current version when a delete event arrives.”
↩︎ The clauses that make a CDC flow correct - 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.https://docs.databricks.com/aws/en/ldp/cdc-advancedOfficial docs
“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.
“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.https://docs.databricks.com/aws/en/icebergOfficial docs
“Managed Iceberg materialized views are in Public Preview.”
↩︎ Making the CDC target readable as Iceberg - 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