Change Data Capture: Tracking Database Changes with CDC

Compare log-based, trigger-based, and polling CDC. See how snapshot handoff, offsets, duplicates, ordering, schema changes, and deletes affect consumers.

published: reading time: 7 min read author: Geek Workbench updated: November 8, 2026
Quick Summary

Change data capture moves database changes to downstream consumers through logs, triggers, or polling. Guarantees depend on the connector and mode: snapshot handoff, offsets, ordering, duplicates, schema changes, and deletes need explicit handling. This guide uses Debezium 3.7 for a scoped MySQL example and explains the operational checks to make.

Change Data Capture: Tracking Database Changes with CDC

Change data capture (CDC) transfers selected database changes to other systems. A search index, warehouse, or service can consume those changes without periodically scanning every source table. CDC avoids application-level dual writes in some designs, but it adds a connector, a change stream, and a recovery process that must be operated.

Coverage and guarantees depend on the source database, connector, capture mode, configuration, and destination. This guide uses the Debezium 3.7 MySQL connector documentation, checked 2026-11-08, as one specific example. Its settings and event shape do not automatically apply to PostgreSQL or another Debezium connector.

How a CDC stream is produced

A log-based connector reads a supported database transaction log and translates configured row changes into events. A broker can distribute those events to independent consumers.

flowchart LR
    App[Application] --> DB[(Source database)]
    DB --> Log[Transaction log]
    Log --> C[CDC connector]
    C --> B[Broker or stream]
    B --> I[Search index]
    B --> W[Warehouse]
    B --> S[Other service]

Log-based capture can avoid repeated polling queries and application changes for every write. The source still generates logs, retains them while the connector needs them, and serves connector reads. Measure source and connector load for the database and mode you use.

Other capture approaches have different costs:

Approach How it finds changes Main trade-off
Log-based CDC Reads a supported transaction log. Low-latency change stream, with log access, retention, and connector operations to manage.
Trigger-based CDC A database trigger writes a change record when a configured row operation occurs. Captures changes in the write transaction but adds work to that path and requires trigger maintenance.
Polling Repeatedly queries for rows newer than a cursor or timestamp. Easy to start for low-volume syncs, but adds query load and needs a reliable cursor and delete strategy.

If consumers need business events such as InvoicePaid, row changes alone may not express that intent. Publish domain events through the application or use an outbox pattern when that is the system’s contract.

Event shape depends on the connector

A change event may include the operation, before and after row values, and source-position metadata. Fields vary by database, connector, capture mode, and table settings. This is an illustrative Debezium-style MySQL event, not a universal schema:

{
  "op": "u",
  "ts_ms": 1711523456789,
  "before": {
    "id": 12345,
    "loyalty_tier": "silver"
  },
  "after": {
    "id": 12345,
    "loyalty_tier": "gold"
  },
  "source": {
    "db": "orders_db",
    "table": "customers",
    "file": "mysql-bin.000003",
    "pos": 570,
    "row": 0
  }
}

Debezium’s MySQL connector documents operation codes and source metadata in its event reference. Before and after images depend on source capabilities and connector configuration. On a compacted Kafka topic, a delete envelope may be followed by a tombstone record with the same key and a null value. Consumers need to handle both records according to the connector’s configuration.

Snapshot and stream handoff

A transaction log contains changes from a retained position; it may not contain the current state of older rows. A connector can take an initial snapshot, establish a log position for the handoff, then stream changes from that position. The database and connector determine how the snapshot boundary is established.

Snapshot modes and recovery procedures are connector-specific. Before deployment, check how the chosen connector handles a consistent snapshot, how it records offsets and schema history, and what it does if the saved position is no longer available. A large snapshot can run long enough for source-log retention to become a capacity issue.

Failure timeline: connector offline past retention

Illustrative scenario: A MySQL connector records a binlog position, publishes events, and stores offsets. The connector then stays offline longer than the source’s binlog retention window. When it restarts, the binlog segment it needs has already been removed.

The saved offset cannot recreate missing changes. Recovery may require a new snapshot and reconciliation with downstream state. If the connector also replays events after a crash, consumers must tolerate duplicates. Retention should cover snapshot duration, expected downtime, and catch-up time, with enough margin for uncertainty.

Ordering, offsets, and replay

A connector may preserve order within a source log or another documented boundary. After events are split across topics or broker partitions, do not assume one total order across tables and partitions. Check the ordering guarantees and transaction metadata for the connector and destination you run.

Plan for replay. A failure can happen after an event is published but before progress is durably recorded across the full pipeline. Consumers should apply changes idempotently, for example by recording a stable event key or source position with the result. If a source log segment has expired, replay is impossible from that offset alone; use the connector’s recovery process or rebuild from a source snapshot.

A delete can have more than one representation. Some connectors emit a delete event and then a tombstone for compaction; some modes can represent deletes differently or omit them. Test the exact event flow before using CDC to maintain a search index, cache, or replicated table.

Schema changes and consumers

A source DDL change can alter later event schemas or stop a connector, depending on the connector and its schema-history configuration. Check how the selected version records schema changes, and test consumer compatibility before deploying DDL. Coordinate renames and drops with downstream consumers; a consumer that assumes an old field exists can fail even while the connector is healthy.

Give the connector only the source privileges it needs, secure credentials and broker access, and limit captured columns when the connector supports it. CDC topics, schema history, snapshots, and dead-letter streams can all retain sensitive data, so include them in data retention and deletion procedures.

Size and monitor the pipeline

Measure log production, connector throughput, serialized event size, broker capacity, and consumer lag under representative traffic. Row count alone is not enough: row width, before/after images, schema, and serialization affect the event volume.

Watch connector heartbeat, source-log lag, snapshot progress, consumer lag by partition, refresh or sink errors, and source storage used by retained logs. Set alert thresholds from the downstream freshness objective and the time available before required log segments expire. If a consumer stalls, the retained log can become a source-storage risk.

When CDC fits

CDC can fit when several downstream consumers need selected row changes and the source exposes a supported capture method. It may be too much machinery for a low-volume sync that can run in a scheduled batch, or when the database service does not expose the log access and retention the connector needs.

CDC also does not replace an application-level event contract. A row update can show that a record changed; it may not explain why the business considers that change meaningful. Choose the stream based on what consumers need to know.

Further Reading

Interview Questions

1. Why does a connector need an initial snapshot?

A log only contains changes from a retained position onward. A snapshot can seed downstream state with existing rows before the connector continues from its coordinated log position.

2. What should a consumer assume about duplicate events?

Assume replay is possible unless the full source-to-sink path documents stronger guarantees. Make updates idempotent or track a stable source position so a repeated event does not apply twice.

3. Does CDC preserve global order across all tables?

Not necessarily. Order depends on the connector's source-log boundary and how events are partitioned downstream. Verify the guarantees for the selected connector and broker configuration.

4. What can happen if a connector is offline past log retention?

The saved position may refer to a log segment the database has removed. The connector cannot continue from that offset and may need a new snapshot or another documented recovery procedure.

Category

Related Posts

Data Migration: Strategies and Patterns for Moving Data

Plan data movement between systems with CDC, staged cutovers, validation gates, and recovery paths. Learn where schema migration is a separate concern.

#data-engineering #data-migration #cdc

Dead Letter Queues: Handling Message Failures Gracefully

Design and implement Dead Letter Queues for reliable message processing. Learn DLQ patterns, retry strategies, monitoring, and recovery workflows.

#data-engineering #dead-letter-queue #kafka

Exactly-Once Semantics in Stream Processing

Exactly-once processing means results appear once within a boundary. Learn how Kafka transactions, checkpoints, and idempotent sinks shape that guarantee.

#data-engineering #exactly-once #stream-processing