CDC
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Change data capture (CDC): the 60-second story

    Change data capture

    Your search still sells a product you deleted.

    A poller asked “what changed since 10:00?” A deleted row matches no query, so nobody downstream ever heard.

    Three places to tap a write: table, transaction or log

    Polling asks the table later, a trigger adds work to every write, and a log reader follows what the database writes anyway.

    Poll by updated_at?

    Bad: Newer than the watermark

    A slow transaction stamps 10:00:05, commits at :12, and falls behind the watermark forever.

    Good: Read the log

    Every change after commit, in commit order, deletes and old values included.

    WAL → replication slot → Debezium → a topic per table

    Each message is keyed by primary key, so one row’s changes stay in one partition, in order. Consumers read at their own pace.

    Inside a Debezium change event

    1. before and after hold the row images
    2. op is c, u, d, or r for snapshot reads
    3. source carries table, transaction and log position
    4. A delete is followed by a tombstone

    A snapshot copies a chunk while live changes stream. Which copy of a row wins?

    The trick

    Bracket the read with low and high watermarks. Any key the log touches in between drops its snapshot row.

    Consume it how?

    Bad: Insert every event

    Redelivery after a crash duplicates rows.

    Good: Upsert by primary key

    Drop stale versions, delete on d, and treat r as an upsert.

    6.9 h

    until a stalled slot fills 500 GB

    At 20 MB of WAL a second, a slot whose connector stopped holds 72 GB an hour. Cap it with max_slot_wal_keep_size and alert.

    Remember

    Follow the log, not the tables. Every committed change, in order per row, at least once, so consumers upsert by key.