Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Applies CDC events from Debezium, Kafka, binlog or logical-replication streams to a sink table as idempotent keyed upserts and deletes.
Use this skill ↓4 of 13 test cases passed with the skill.
3 of 3 safety checks passed
477 agent runs
A CDC stream is not a log of things to append. Each event describes what happened to one row in a source table — it was created, changed, or deleted — and your job is to make the sink reflect the source's current state, not to accumulate one row per event. The base default is to deserialize each event and INSERT it. That is wrong: one row's create → update → update becomes three sink rows, deleted rows never disappear, a redelivered event double-counts, and a null-value record crashes the parser. Apply all five rules below.
A typical event (Debezium envelope shown; binlog and logical-replication payloads carry the same fields under other names):
{
"op": "u", // c=create/insert, u=update, d=delete, r=snapshot read
"before": { "id": 7, "email": "a@x" },
"after": { "id": 7, "email": "b@x" },
"source": { "lsn": 402096, "ts_ms": 1710000000123 }
}
Read the op field and take a different action per type; never treat the whole stream as inserts.
after image (insert-or-replace on the key).after image to the existing key (the new state; before is only the prior value, for diffing). An update is an upsert, not a second row.before; after is null.after image, same keyed apply as an insert. Snapshot reads represent rows that already exist; upserting makes them idempotent with the live events that follow.If you INSERT every event regardless of op, updates fan out into duplicate rows and deletes are silently ignored. The sink drifts from the source and nothing errors.
On a log-compacted topic, a delete is often followed by a tombstone: a record with the key populated and the value/payload null. It is not a row and not an insert — it is a marker that the key is gone, emitted so compaction can garbage-collect that key's history. A consumer that blindly deserializes value.after will throw a null-pointer error or write a blank/garbage row.
Detect the null-value record before parsing. What to do with it depends on the source config:
d event, the tombstone is redundant — skip it; the d already carried the delete.d), the null-value record is the delete signal — act on it and remove/soft-delete the key.Either way, a tombstone is never data.
Correctness depends on applying a key's events in commit order, and each event carries a monotonic position: Postgres LSN, MySQL binlog file+position, a Kafka partition offset, or a source sequence / ts_ms. CDC connectors key each event by the row's primary key, so one row's events land on one partition in order — within a partition, offset order is commit order.
Next to this one in the catalogue, plus more from the same author.