liveBook · Manning

Change-data-capture

As explained in ScyllaDB in Action

Change data capture is a database feature that records table mutations in a change-log table so they can be consumed over time.

Change data capture (CDC) records mutations to a configured table in a corresponding CDC log table. Instead of repeatedly scanning a large table to learn what changed, a consumer can query recorded changes over time and apply them to another system. section 12.1.2 section 12.3

CDC records changes, not a complete copy of each row. A log entry includes fields written by the mutation; a value left untouched by an UPDATE is not repeated merely because it exists in the base row. This makes the log useful for reconstructing a timeline of writes, but consumers must treat each entry as a change event rather than current row state. section 12.1.2 section 12.3

Using CDC involves a small set of database-aware steps:

  • Enable CDC per table with the cdc table property; it can also be enabled when creating the table. section 12.1.2
  • Find the generated CDC log table, which stores base-table fields alongside CDC metadata such as stream ID, time, batch sequence number, operation, and deletion markers. section 12.1.2
  • Query changes by stream ID. Stream IDs are created for stream generations, so queries must account for multiple generations when topology changes. section 12.1.2 section 12.3
  • Ingest the resulting events into a secondary store for exports, aggregation, analysis, or an audit-style history of who changed which fields. section 12.1.2

Tracking an author update

Enable CDC for the restaurant-review application's authors table, then insert Charlie Change with a name and bio. The CDC log receives an entry containing those written values. Updating only the bio produces another entry for the bio change; the name is absent from that update entry because the UPDATE did not change it. Adding an edited_by value on each write can let a downstream system build a timeline of article edits. section 12.1.2

cqlsh:reviews> DESCRIBE reviews;
...

CREATE TABLE reviews.authors_scylla_cdc_log (    #1
    "cdc$stream_id" blob,
    "cdc$time" timeuuid,
    "cdc$batch_seq_no" int,
    bio text,                    #2
    "cdc$deleted_bio" boolean,          #3
    "cdc$deleted_elements_image" frozen<set<smallint>>,
    "cdc$deleted_image" boolean,
    "cdc$deleted_name" boolean,
    "cdc$end_of_batch" boolean,
    "cdc$operation" tinyint,
    "cdc$ttl" bigint,
    id timeuuid,
    image frozen<image>,
    name text,
    PRIMARY KEY ("cdc$stream_id", "cdc$time", "cdc$batch_seq_no")    #4
) WITH CLUSTERING ORDER BY ("cdc$time" ASC, "cdc$batch_seq_no" ASC)
...

The generated log-table definition makes CDC concrete: stream ID, time, and batch sequence number form its key, while operation and deletion fields describe the mutation alongside changed data. section 12.1.2

How ScyllaDB in Action covers it

How deep it goes
Explains per-table configuration, generated log fields, partial-update behavior, stream queries, and topology-driven stream generations.
Examples
Demonstrates enabling CDC on authors, inserting Charlie Change, updating a bio, and inspecting the resulting log rows.
What it assumes
Introduces CDC from table mutations and assumes familiarity with tables, inserts, updates, and queries.
What you can do after
Operate/configure it by enabling CDC, locating its log table, and querying changes through stream IDs.
How it connects
Connects CDC to data exports, secondary data stores, stream IDs, stream generations, topology changes, and data migration.

Also explained in

Compare how 5 books explain change-data-capture →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.