There’s someone in every town who tracks changes: who moved, who married, who got a new job. They don’t track static facts (John lives on Oak Street). They track changes (John moved from Oak to Elm).
That’s Change Data Capture (CDC): the gossip column of the database world, recording every alteration so downstream systems can stay informed.
Alternatives
Daily Snapshots
The town newspaper takes daily photos of the entire town. To find what changed between Monday and Tuesday, compare millions of pixels. Most are identical. Huge waste of effort. Still miss quick changes.
Photocopying the phone book daily to find who moved.
Polling
Citizens constantly asking: “Did anything change?”
- “Did John move?” No.
- “Did Mary get married?” No.
- (5 seconds later) “Did John move?” Still no.
Constant questioning overwhelms everyone, still misses changes between polls.
CDC Approach
Mrs. Data-Capture tracks events instead of state:
Monday’s Journal:
- 9:15 AM: John Smith moved from Oak St. to Elm St.
- 10:30 AM: Mary Johnson married Tom Wilson
- 2:45 PM: Bob Davis started job at New Company
- 4:00 PM: Alice Cooper painted house from white to blue
Each entry captures when, what changed, old value, new value.
Subscriptions
Citizens subscribe to topics they care about:
- Real Estate Agent: “Tell me about all address changes”
- Wedding Planner: “Notify me of all marriages”
- HR Director: “Alert me to job changes”
Mrs. Data-Capture ensures each subscriber gets exactly the changes they need.
This diagram requires JavaScript.
Enable JavaScript in your browser to use this feature.
Capture Methods
Transaction Log
Every database keeps a transaction log:
- Insert: “New resident arrived”
- Update: “Resident changed address”
- Delete: “Resident moved away”
CDC reads this log and publishes changes. Like having access to the town clerk’s official records as they’re written.
Trigger-Based
Each change triggers a notification. Immediate but can slow down actual changes.
Query-Based
Every hour, compare current state to last known state. Note differences, publish changes. Less immediate but doesn’t slow operations.
Use Cases
Retail Inventory
Without CDC: Every hour, copy entire inventory to website. 100,000 products × 24 times/day. Massive transfer. Website shows hour-old data.
With CDC:
- 10:15 AM: “Widget qty changed from 50 to 49”
- 10:16 AM: “Gadget price changed from $10 to $9”
- 10:17 AM: “Doohickey added to inventory”
Website updates within seconds. Transfer reduced by 99%.
Data Warehouse
Traditional: Nightly batch job copies entire database, 8-hour process, analytics always day behind.
CDC: Stream changes continuously, data warehouse stays current, analytics near real-time.
Audit Trail
Every change captured: who changed it, when, what it was before, what it became. Perfect audit trail with no extra effort.
Challenges
Initial Snapshot
Need current state + future changes. Take snapshot of entire database, start capturing changes from that point. Risk: changes during snapshot.
Solution: Consistent snapshot + change capture from that point.
Out-of-Order
Network delays cause gossip to arrive out of order:
- “John divorced at 2 PM”
- “John married at 1 PM”
- Arrive reversed
CDC must include timestamps and handle reordering.
Deletes
Someone leaves town:
Option 1: “John deleted” Option 2: “John moved to Unknown” Option 3: Keep record with “inactive” flag
Different systems need different approaches.
Decision Rules
CDC works when:
- Multiple systems need to stay synchronized
- Change history matters (auditing, time-travel queries)
- You want to reduce polling overhead
CDC adds complexity. Only use when the benefits justify it.