What is Change Data Capture (CDC) in MySQL?
Answer
Change Data Capture (CDC) is a technique for tracking and capturing data changes (inserts, updates, deletes) in a database as they happen, and streaming those changes to other systems in real-time. In MySQL, CDC is typically implemented by reading the binary log (binlog), which records all data modifications. Popular CDC tools for MySQL: (1) Debezium: open-source, streams binlog events to Apache Kafka as structured change events; supports MySQL, PostgreSQL, MongoDB. The Kafka topic gets an event for every row change with before/after values; (2) AWS DMS (Database Migration Service): managed CDC for cloud migrations and ongoing replication; (3) Maxwell's Daemon: MySQL binlog to Kafka/Kinesis/stdout; (4) Tungsten Replicator. Requirements: MySQL binlog must be enabled, format set to ROW, and the CDC tool given REPLICATION SLAVE and REPLICATION CLIENT privileges. Use cases: (1) Syncing data to Elasticsearch for search; (2) Updating Redis cache when DB changes; (3) Building event-driven microservices that react to data changes; (4) Audit logs; (5) Real-time analytics pipelines; (6) Zero-downtime database migrations. CDC is more reliable than polling (SELECT WHERE updated_at > last_check) because soft deletes and timing gaps can miss changes.
Previous
What are common SQL anti-patterns to avoid?
Next
How do you implement pagination efficiently in MySQL?
More MySQL / SQL Questions
View all →- Advanced What is the difference between B-tree and Hash indexes in MySQL?
- Advanced What is MVCC (Multi-Version Concurrency Control) in MySQL?
- Advanced What is the InnoDB Buffer Pool and how does it work?
- Advanced What is deadlock in MySQL and how do you prevent it?
- Advanced What is the query execution plan and how does the MySQL optimizer work?