Same day, 6 changes: the snapshot diff saw 3 of 6, the change log caught 6 of 6.
python3 --version.git clone https://github.com/DayanEbrar0X/data-anatomy.ai.git cd data-anatomy.ai
python3 -m venv .venv source .venv/bin/activate
cd data-engineering/17-change-data-capture python3 src/cdc.py
from shop import source, triggers, snap, diff, DAY
src = source() # orders 1 and 2: 'new'
triggers(src) # every write -> changes
yday = snap(src) # last night's snapshot
src.executescript(DAY) # six writes today
seen = diff(yday, snap(src))
log = list(src.execute("SELECT * FROM changes"))
print(f"nightly diff: {len(seen)} of {len(log)}"
f" | cdc: {len(log)} of {len(log)}")Your nightly job missed 3 updates. CDC catches every one. Change data capture logs every write, the moment it happens. Our orders table gets six writes today.
A trigger logs each write to a changes table, standing in for the log Debezium reads. The nightly job diffs last night's snapshot against tonight's. CDC just reads the log. Run it.
The diff saw three of six. CDC caught all six. A snapshot shows where you ended. The log shows how you got there.
Read the lesson on GitHub →