Problem
Periodic full or timestamp-based extracts load operational databases, miss hard deletes and deliver data hours late. Dual writes from applications to analytics risk inconsistency.
Also known as: cdc-to-warehouse, log-based-replication-pipeline
Stream committed database changes from the transaction log into analytics stores with low latency and low source impact.
Periodic full or timestamp-based extracts load operational databases, miss hard deletes and deliver data hours late. Dual writes from applications to analytics risk inconsistency.
A change data capture pipeline turns a database's commit log into a stream of row-level change events and delivers them to analytical systems. Compared with polling for updated timestamps, log reading sees every change, including deletes, in commit order.
A connector attaches to the log, performs an initial snapshot, then tails changes. Each event holds the key, before and after images, operation type and source position.
OLTP DB --WAL--> connector --> topic db.orders (key = order_id)
|--> sink: MERGE into warehouse.orders
Applying events downstream usually follows this merge, with the latest event per key winning:
MERGE INTO dw.orders t USING staged_changes s ON t.order_id = s.order_id
WHEN MATCHED AND s.op = 'd' THEN DELETE
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED AND s.op <> 'd' THEN INSERT *;
Delivery is at least once, so applying by key with the source log position as a tiebreaker makes replays harmless. A history table of all events supports audit and slowly changing dimensions. See the cdc pattern for the general technique.
Medium - connector cluster and event log
Medium - monitoring lag and replication slots
Medium - ordering and merge semantics
Unconsumed replication slot fills source disk
Connector restart replays events causing duplicates
Source schema change breaks downstream parsing