Getting Started: Your First Change Events

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Every later page in this section assumes one picture in the reader’s head: a database commits a change, a Debezium connector running inside Kafka Connect reads that change from the database log, and a Kafka topic receives one event that describes it. This page builds that picture with real software in a few minutes. It is the official Debezium Kafka Connect tutorial, rebuilt as a single Docker Compose file and pinned to the 3.7.1.Final images, followed by the same lab against PostgreSQL.

The tutorial uses the small inventory sample database that Debezium ships in its example images, not the Bookshop schema of the rest of the section. That is on purpose: the goal here is to see the mechanics (snapshot, streaming, offsets, restarts) with nothing else in the way. Once those mechanics are familiar, the same steps apply to the legacy Bookshop Oracle database in Oracle Connector and Worked Example: Oracle to PostgreSQL.

Why this matters for a migration: during a strangler-fig migration (see Migration Path: From a Legacy Stack to a Modern One) the new system depends on three guarantees that this lab lets you observe directly:

  1. the existing rows are copied once, as r (read) events, before streaming starts;

  2. every committed insert, update and delete after that appears as a c, u or d event, in commit order per row;

  3. if the capture process stops, it resumes from the exact log position it had reached, so changes made while it was down are delivered late but not lost.

Checked on 2026-11-09 against Debezium 3.7.1.Final, with Kafka 4.3.1 (KRaft mode, bundled in the Debezium images), MySQL 8.2.0 (example-mysql) and PostgreSQL 18.6 (example-postgres). The Compose stack, both connector configurations and every command on this page were run with Docker on 2026-11-09, and the event output shown is the real output of that run, trimmed for width. The page uses the standard host ports (9092, 8083, 3306 and 5432).

What you build

The stack has four containers on one Docker network, plus short-lived client containers that you start when you need them.

flowchart LR subgraph compose["Docker Compose project dbz-tutorial"] mysql[("mysql: example-mysql")] postgres[("postgres: example-postgres")] connect["connect: Kafka Connect with Debezium, REST on 8083"] kafka[["kafka: KRaft node on 9092"]] end host["Terminal: curl and docker compose exec"] watcher["watch-topic or kcat client container"] mysql -- "binlog" --> connect postgres -- "logical replication slot" --> connect connect -- "change events and offsets" --> kafka host -- "REST API" --> connect watcher -- "consume topics" --> kafka

The roles are the same as in a production migration pipeline (see Debezium Architecture):

  • Kafka stores the change-event topics and the three internal Kafka Connect topics (connector configurations, source offsets and connector status).

  • Kafka Connect runs the Debezium connector plugins. You never start a connector process yourself: you send a JSON configuration to the Connect REST API, and Connect starts the connector and its task.

  • The source databases are preconfigured for change data capture. The MySQL image has the binlog enabled in ROW format with full row images and a debezium user with replication privileges. The PostgreSQL image runs with wal_level=logical.

Prerequisites

  • Docker Engine or Docker Desktop with the Compose plugin (docker compose version prints v2.x).

  • About 3 GB of free memory for the containers. Without a heap limit, the Kafka Connect container can be killed by the out-of-memory killer on a machine with little free memory, so the Compose file below caps its heap (the HEAP_OPTS line). If docker compose ps shows connect as Exited (137), give Docker more memory or stop other containers.

  • curl and jq on the host. jq is only used to pretty-print and trim JSON.

  • Free host ports 9092, 8083, 3306 and 5432. If one is taken, change only the left-hand side of the matching ports entry and use that port in the commands.

Step 1: Start the services

The official tutorial starts Kafka, MySQL and Kafka Connect with one docker run command each, in separate terminals. The Compose file below starts the same containers with the same environment variables in one step, and adds the PostgreSQL example database used in the second half of the page.

compose.yaml — Kafka (KRaft), Kafka Connect and the example MySQL and PostgreSQL databases
name: dbz-tutorial

services:
  kafka:
    image: quay.io/debezium/kafka:3.7.1.Final
    hostname: kafka
    ports:
      - "9092:9094"
    environment:
      CLUSTER_ID: 5Yr1SIgYQz-b-dgRabWx4g
      NODE_ID: "1"
      NODE_ROLE: combined
      KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093
      KAFKA_LISTENERS: PLAINTEXT://kafka:9092,CONTROLLER://kafka:9093,EXTERNAL://0.0.0.0:9094
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,EXTERNAL://localhost:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,EXTERNAL:PLAINTEXT

  mysql:
    image: quay.io/debezium/example-mysql:3.7.1.Final
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: debezium
      MYSQL_USER: mysqluser
      MYSQL_PASSWORD: mysqlpw

  postgres:
    image: quay.io/debezium/example-postgres:3.7.1.Final
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres

  connect:
    image: quay.io/debezium/connect:3.7.1.Final
    ports:
      - "8083:8083"
    depends_on:
      - kafka
      - mysql
      - postgres
    environment:
      GROUP_ID: "1"
      BOOTSTRAP_SERVERS: kafka:9092
      CONFIG_STORAGE_TOPIC: my_connect_configs
      OFFSET_STORAGE_TOPIC: my_connect_offsets
      STATUS_STORAGE_TOPIC: my_connect_statuses
      HEAP_OPTS: -Xms256m -Xmx512m

What each part does, and where it differs from the official docker run commands:

kafka

A single Kafka 4.x node in KRaft mode (no ZooKeeper) that is both broker and controller (NODE_ROLE: combined). CLUSTER_ID, NODE_ID, NODE_ROLE, KAFKA_CONTROLLER_QUORUM_VOTERS, KAFKA_LISTENERS and KAFKA_ADVERTISED_LISTENERS are the variables from the official Starting Kafka step. The cluster ID is any 22-character base64 UUID; generate your own with docker run --rm quay.io/debezium/kafka:3.7.1.Final /kafka/bin/kafka-storage.sh random-uuid if you prefer. The image’s entry point turns every KAFKA_* variable into a server.properties entry, formats the storage directory on first start, and prints a warning that KAFKA_CONTROLLER_QUORUM_VOTERS is deprecated since Kafka 4.1.1. It converts the value to controller.quorum.bootstrap.servers itself, so the warning is harmless here.
The official command advertises only kafka:9092, which works for clients inside the Docker network but not for a client on the host. This file adds a third listener, EXTERNAL, that listens on container port 9094, is published as host port 9092 and advertises localhost:9092. Containers keep using kafka:9092; host tools such as a local kcat or a Spring Boot application started from the IDE use localhost:9092.

mysql

The example-mysql image (based on MySQL 8.2) with the inventory sample database. The variables are those of the official Starting a MySQL database step. The image also creates the debezium user (password dbz) that the connector uses.

postgres

The example-postgres image (PostgreSQL 18 with wal_level=logical) with the same inventory data in a schema called inventory. It is only needed for the second half of the page.

connect

Kafka Connect with every Debezium connector plugin already installed. GROUP_ID, BOOTSTRAP_SERVERS and the three *_STORAGE_TOPIC variables are those of the official Starting Kafka Connect step. The storage topics are where Kafka Connect keeps connector configurations, source offsets and status, which is why connectors survive a restart of the Connect container. HEAP_OPTS caps the JVM heap so that the stack fits on a laptop. Compose service names resolve as host names on the project network, so the --link options of the official commands are not needed.

Start the stack and wait until Kafka Connect answers:

Start the stack and check Kafka Connect
docker compose up -d

# Repeat until it answers (Kafka Connect needs 20-60 seconds to scan its plugins)
curl -s -H "Accept:application/json" localhost:8083/ | jq .
Output on 2026-11-09
{
  "version": "4.3.1",
  "commit": "26b251a451ce941d",
  "kafka_cluster_id": "5Yr1SIgYQz-b-dgRabWx4g"
}

The version is the Kafka Connect version, not the Debezium version. To see which Debezium plugins the worker loaded, and their versions, list the connector plugins:

List the installed source connector plugins
curl -s localhost:8083/connector-plugins | jq -c '.[] | select(.type == "source")'
Output on 2026-11-09 (trimmed)
{"class":"io.debezium.connector.mariadb.MariaDbConnector","type":"source","version":"3.7.1.Final"}
{"class":"io.debezium.connector.mongodb.MongoDbConnector","type":"source","version":"3.7.1.Final"}
{"class":"io.debezium.connector.mysql.MySqlConnector","type":"source","version":"3.7.1.Final"}
{"class":"io.debezium.connector.oracle.OracleConnector","type":"source","version":"3.7.1.Final"}
{"class":"io.debezium.connector.postgresql.PostgresConnector","type":"source","version":"3.7.1.Final"}
{"class":"io.debezium.connector.sqlserver.SqlServerConnector","type":"source","version":"3.7.1.Final"}

The full list also contains the Db2, Informix, Spanner, Vitess, CockroachDB and Db2 for IBM i source connectors, the JDBC and MongoDB sink connectors, and the Kafka MirrorMaker connectors. Some of those Debezium connectors are incubating; see Db2, Informix, Cassandra & Others. Finally, check that no connector is registered yet:

List registered connectors
curl -s -H "Accept:application/json" localhost:8083/connectors/
# []

Look at the sample data before you change it. docker compose exec runs the MySQL client inside the mysql container, so no client is needed on the host:

Query the customers table
docker compose exec mysql mysql -umysqluser -pmysqlpw inventory -e "SELECT * FROM customers"
Output on 2026-11-09
id      first_name      last_name       email
1001    Sally           Thomas          sally.thomas@acme.com
1002    George          Bailey          gbailey@foobar.com
1003    Edward          Walker          ed@walker.com
1004    Anne            Kretchmar       annek@noanswer.org

Step 2: Register the MySQL connector

A connector is a JSON document with a name and a config map. Save the following as register-mysql.json. It is the configuration of the official tutorial, unchanged.

register-mysql.json — Debezium MySQL connector for the inventory database
{
  "name": "inventory-connector",
  "config": {
    "connector.class": "io.debezium.connector.mysql.MySqlConnector",
    "tasks.max": "1",
    "database.hostname": "mysql",
    "database.port": "3306",
    "database.user": "debezium",
    "database.password": "dbz",
    "database.server.id": "184054",
    "topic.prefix": "dbserver1",
    "database.include.list": "inventory",
    "schema.history.internal.kafka.bootstrap.servers": "kafka:9092",
    "schema.history.internal.kafka.topic": "schemahistory.inventory"
  }
}

The properties, and what each one means in a real migration:

Property Value here Why it matters

connector.class

MySqlConnector

Selects the plugin. Each source database has its own class; see MySQL & MariaDB Connectors.

tasks.max

1

The MySQL connector always runs a single task, because the binlog is one ordered stream. A single reader keeps the order of events.

database.hostname, database.port

mysql, 3306

The address as seen from the Connect container, not from your host. A common mistake is localhost, which points at the Connect container itself.

database.user, database.password

debezium, dbz

A dedicated user with SELECT, RELOAD, SHOW DATABASES, REPLICATION SLAVE, REPLICATION CLIENT. In production, never put the password in plain text: use a Kafka Connect config provider (see Security & Data Protection).

database.server.id

184054

The connector joins the MySQL replication topology as a replica, so it needs a server ID that is unique among all replicas of that server.

topic.prefix

dbserver1

The logical name of the source. Every topic starts with it (dbserver1.inventory.customers), and Debezium stores offsets under it. Never change it on a running connector: a new prefix means new topics and a fresh snapshot. topic.prefix replaced the old database.server.name.

database.include.list

inventory

Only this database is captured.

schema.history.internal.kafka.*

kafka:9092, schemahistory.inventory

MySQL binlog events do not carry the table structure, so the connector records every DDL statement in this topic and replays it after a restart. These properties replaced the old database.history.* names.

Register the connector with a POST to /connectors:

Register the MySQL connector
curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" \
  localhost:8083/connectors/ -d @register-mysql.json
Response on 2026-11-09 (body trimmed)
HTTP/1.1 201 Created
Server: Jetty(12.0.34)
Location: http://localhost:8083/connectors/inventory-connector
Content-Type: application/json

{"name":"inventory-connector","config":{"connector.class":"io.debezium.connector.mysql.MySqlConnector", ... },"tasks":[],"type":"source"}

201 Created only means that Kafka Connect stored the configuration. Whether the connector actually started is a separate question, answered by the status endpoint:

Check the connector and task state
curl -s localhost:8083/connectors/inventory-connector/status | jq .
Output on 2026-11-09
{
  "name": "inventory-connector",
  "connector": {
    "state": "RUNNING",
    "worker_id": "172.18.0.5:8083",
    "version": "3.7.1.Final"
  },
  "tasks": [
    {
      "id": 0,
      "state": "RUNNING",
      "worker_id": "172.18.0.5:8083",
      "version": "3.7.1.Final"
    }
  ],
  "type": "source"
}

Both the connector and task 0 must be RUNNING. If the task is FAILED, the status response contains a trace field with the Java stack trace. The usual causes in this lab are a wrong host name, a wrong password, or a database that is not ready yet. Fix the configuration with PUT /connectors/inventory-connector/config and the task restarts.

Watch the connector start

The Connect log shows the snapshot workflow that Initial Snapshots explains in detail. These are the key lines from the run, with the logger names removed:

Read the Connect log
docker compose logs connect | grep -E 'Snapshot step|Snapshot ended|Starting streaming|Connected to binlog|using binlog'
Output on 2026-11-09 (trimmed)
08:51:12,261 INFO   MySQL||snapshot  Snapshot step 1 - Preparing
08:51:12,266 INFO   MySQL||snapshot  Snapshot step 2 - Determining captured tables
08:51:12,353 INFO   MySQL||snapshot  Snapshot step 3 - Locking captured tables [inventory.addresses, inventory.customers, inventory.geom, inventory.orders, inventory.products, inventory.products_on_hand]
08:51:12,356 INFO   MySQL||snapshot  Flush and obtain global read lock to prevent writes to database
08:51:12,358 INFO   MySQL||snapshot  Snapshot step 4 - Determining snapshot offset
08:51:12,361 INFO   MySQL||snapshot       using binlog 'mysql-bin.000003' at position '157' and gtid ''
08:51:12,361 INFO   MySQL||snapshot  Snapshot step 5 - Reading structure of captured tables
08:51:12,631 INFO   MySQL||snapshot  Snapshot step 6 - Persisting schema history
08:51:12,663 INFO   MySQL||snapshot  Snapshot step 7 - Snapshotting data
08:51:12,736 INFO   MySQL||snapshot  Snapshot completed
08:51:12,767 INFO   MySQL||streaming  Starting streaming
08:51:12,837 INFO   MySQL||binlog  Connected to binlog at mysql:3306, starting at BinlogOffsetContext{... currentBinlogFilename='mysql-bin.000003', currentBinlogPosition=157, ...}

Read the two binlog positions together. In step 4 the connector recorded mysql-bin.000003 position 157 while it held the read lock, then copied the rows, and finally connected to the binlog at exactly that position. Anything committed during the copy is therefore delivered as a streaming event after the snapshot events, never lost and never mixed in. That hand-over is what makes a snapshot plus streaming a correct baseline for a migration.

The connector creates one topic per captured table, plus the schema change topic named after the prefix and the schema history topic:

List the topics
docker compose exec kafka /kafka/bin/kafka-topics.sh --bootstrap-server kafka:9092 --list
Output on 2026-11-09
__consumer_offsets
dbserver1
dbserver1.inventory.addresses
dbserver1.inventory.customers
dbserver1.inventory.geom
dbserver1.inventory.orders
dbserver1.inventory.products
dbserver1.inventory.products_on_hand
my_connect_configs
my_connect_offsets
my_connect_statuses
schemahistory.inventory

The topic name is <topic.prefix>.<database>.<table>. The dbserver1 topic carries schema change events for consumers that want to follow DDL, and schemahistory.inventory is internal to the connector: never consume it as data and never delete it while the connector exists.

Step 3: Watch the customers topic

Open a second terminal and start a consumer that prints every event in dbserver1.inventory.customers from the beginning, with its key. The Debezium Kafka image includes a watch-topic helper for this; it is a thin wrapper around kafka-console-consumer.sh.

Watch the topic with the watch-topic helper
docker run -it --rm --name watcher --network dbz-tutorial_default \
  quay.io/debezium/kafka:3.7.1.Final watch-topic -a -k dbserver1.inventory.customers

-a reads from the beginning of the topic and -k prints the key, separated from the value by a tab. dbz-tutorial_default is the network that Compose created for the project. The plain Kafka console consumer works the same way and is what you would script:

The same, with kafka-console-consumer
docker compose exec kafka /kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka:9092 \
  --topic dbserver1.inventory.customers --from-beginning \
  --formatter-property print.key=true

In Kafka 4.x the console consumer’s --property option is deprecated in favour of --formatter-property; the old spelling still works but prints a warning.

A third option is kcat, which can print the partition offset of every message with a format string. That is useful later for checking that nothing was lost or duplicated:

The same, with kcat, showing the topic offset of each event
docker run --rm --platform linux/amd64 --network dbz-tutorial_default edenhill/kcat:1.7.1 \
  -b kafka:9092 -C -t dbserver1.inventory.customers -o beginning -e -q -f '%o|%s\n'

Reference: kcat — README

The edenhill/kcat image is published for linux/amd64 only, so on an ARM machine Docker runs it under emulation (hence --platform). If kcat is installed on the host, use -b localhost:9092 instead; the EXTERNAL listener in the Compose file exists for exactly this.

The snapshot events

The first four events are the snapshot of the four existing customers. Each message has a key and a value, and with the default JSON converter each of them is a schema plus payload pair. The key of the last snapshot event:

Key of a snapshot event (real output, 2026-11-09)
{
  "schema": {
    "type": "struct",
    "fields": [ { "type": "int32", "optional": false, "field": "id" } ],
    "optional": false,
    "name": "dbserver1.inventory.customers.Key"
  },
  "payload": { "id": 1004 }
}

The key is the primary key of the row. Kafka uses it to choose the partition, so every change to customer 1004 lands in the same partition, in order. Consumers that apply events to a target table rely on that ordering.

The value carries a schema that describes before, after, source, transaction, op and the timestamps, and the payload itself. The schema is around 2.5 KB per message in this table; the payload is the part you work with. With jq -c .payload:

Value payload of the last snapshot event (real output, 2026-11-09)
{
  "before": null,
  "after": { "id": 1004, "first_name": "Anne", "last_name": "Kretchmar", "email": "annek@noanswer.org" },
  "source": {
    "version": "3.7.1.Final", "connector": "mysql", "name": "dbserver1",
    "ts_ms": 1794214272000, "snapshot": "last_in_data_collection",
    "db": "inventory", "sequence": null, "table": "customers",
    "server_id": 0, "gtid": null, "file": "mysql-bin.000003", "pos": 157, "row": 0,
    "thread": null, "query": null,
    "ts_us": 1794214272000000, "ts_ns": 1794214272000000000
  },
  "transaction": null,
  "op": "r",
  "ts_ms": 1794214272715, "ts_us": 1794214272715802, "ts_ns": 1794214272715802176
}
  • op is r (read): this row was copied by the snapshot, not changed by a transaction.

  • before is null and after holds the whole row.

  • source.snapshot marks the position within the snapshot: first_in_data_collection, true, and last_in_data_collection for the last row of this table. Streaming events have "false".

  • source.file and source.pos are the binlog position recorded in snapshot step 4; every snapshot event carries the same position.

Anatomy of a Change Event explains every field. For this lab, the four fields that matter are op, before, after and source.

Step 4: Insert, update and delete rows

Keep the watcher running and change the data from the first terminal.

Insert, update and delete in MySQL
docker compose exec mysql mysql -umysqluser -pmysqlpw inventory -e \
  "INSERT INTO customers (first_name, last_name, email) VALUES ('Lena', 'Okafor', 'lena.okafor@example.com');"

docker compose exec mysql mysql -umysqluser -pmysqlpw inventory -e \
  "UPDATE customers SET first_name='Anne Marie' WHERE id=1004;"

docker compose exec mysql mysql -umysqluser -pmysqlpw inventory -e \
  "DELETE FROM addresses WHERE customer_id=1004; DELETE FROM customers WHERE id=1004;"

The addresses table has a foreign key to customers, so the address rows of customer 1004 must go first, as the official tutorial explains. Both deletes run in one transaction here, so the addresses topic receives its delete events from the same binlog transaction.

The create event

Value payload of the insert (real output, 2026-11-09)
{
  "before": null,
  "after": { "id": 1005, "first_name": "Lena", "last_name": "Okafor", "email": "lena.okafor@example.com" },
  "source": {
    "version": "3.7.1.Final", "connector": "mysql", "name": "dbserver1",
    "ts_ms": 1794214340000, "snapshot": "false", "db": "inventory", "table": "customers",
    "server_id": 223344, "gtid": null, "file": "mysql-bin.000003", "pos": 392, "row": 0,
    "thread": 15, "query": null
  },
  "transaction": null,
  "op": "c",
  "ts_ms": 1794214340823
}

op is now c, source.snapshot is "false", and the binlog position has moved on to 392. source.server_id is the server ID of the MySQL server that wrote the change, and source.thread is the MySQL connection that ran it. source.ts_ms (when MySQL committed the change, with second precision for MySQL) and the top-level ts_ms (when Debezium processed it) differ by 0.8 seconds; that difference is the capture lag, and Monitoring, Logging & Tracing shows how to measure it in production.

The update event

Value payload of the update (real output, 2026-11-09)
{
  "before": { "id": 1004, "first_name": "Anne", "last_name": "Kretchmar", "email": "annek@noanswer.org" },
  "after":  { "id": 1004, "first_name": "Anne Marie", "last_name": "Kretchmar", "email": "annek@noanswer.org" },
  "source": {
    "version": "3.7.1.Final", "connector": "mysql", "name": "dbserver1",
    "ts_ms": 1794214342000, "snapshot": "false", "db": "inventory", "table": "customers",
    "server_id": 223344, "file": "mysql-bin.000003", "pos": 746, "row": 0, "thread": 16
  },
  "transaction": null,
  "op": "u",
  "ts_ms": 1794214342972
}

An update carries the whole row before and after the change, because the example image runs MySQL with binlog_row_image=FULL. A consumer can compare the two images to find out which columns changed (only first_name here). This is information that a polling job reading the current table state never sees; see Migration Strategies.

The delete event and the tombstone

The delete produces two messages with the same key, {"id":1004}:

Value payload of the delete (real output, 2026-11-09)
{
  "before": { "id": 1004, "first_name": "Anne Marie", "last_name": "Kretchmar", "email": "annek@noanswer.org" },
  "after": null,
  "source": {
    "version": "3.7.1.Final", "connector": "mysql", "name": "dbserver1",
    "ts_ms": 1794214345000, "snapshot": "false", "db": "inventory", "table": "customers",
    "server_id": 223344, "file": "mysql-bin.000003", "pos": 1508, "row": 0, "thread": 17
  },
  "transaction": null,
  "op": "d",
  "ts_ms": 1794214345146
}

followed by a message whose value is null, a tombstone:

The tombstone as printed by watch-topic (key, tab, value)
{"schema":{"type":"struct","fields":[{"type":"int32","optional":false,"field":"id"}],"optional":false,"name":"dbserver1.inventory.customers.Key"},"payload":{"id":1004}}	null

The delete event tells consumers what was removed (the before image). The tombstone tells Kafka log compaction that every earlier message with key 1004 may eventually be removed from a compacted topic. Two consequences for a migration pipeline:

  • A consumer that writes to the new database must handle both: apply the d event as a delete, and skip (or treat as a delete) a record with a null value. Code that calls a method on the value without a null check fails on the first tombstone. The JDBC sink handles both with delete.enabled=true; see JDBC Sink Connector.

  • tombstones.on.delete=false on the source connector suppresses the tombstone if no consumer needs compaction. Event flattening has its own options (delete.tombstone.handling.mode); see Event Flattening.

At this point the topic holds eight messages. kcat with the %o format prints the partition offset of each, which gives a compact summary:

Topic content after step 4 (kcat output, summarised with jq)
0 {"op":"r","id":1001,"snapshot":"first_in_data_collection"}
1 {"op":"r","id":1002,"snapshot":"true"}
2 {"op":"r","id":1003,"snapshot":"true"}
3 {"op":"r","id":1004,"snapshot":"last_in_data_collection"}
4 {"op":"c","id":1005,"snapshot":"false"}
5 {"op":"u","id":1004,"snapshot":"false"}
6 {"op":"d","id":1004,"snapshot":"false"}
7 tombstone

Step 5: Stop Kafka Connect, change data, restart

This step shows the property that makes CDC usable for a long-running migration: the connector can be stopped for an upgrade, a crash or a redeployment, and it resumes from where it stopped.

First look at where the connector has recorded its position. Kafka Connect stores source offsets in the my_connect_offsets topic, keyed by connector name and source partition:

Read the stored offsets
docker compose exec kafka /kafka/bin/kafka-console-consumer.sh --bootstrap-server kafka:9092 \
  --topic my_connect_offsets --from-beginning --formatter-property print.key=true --timeout-ms 5000
Output on 2026-11-09, about a minute after step 4
["inventory-connector",{"server":"dbserver1"}]	{"ts_sec":1794214272,"file":"mysql-bin.000003","pos":157}

Only the snapshot position (157) is stored, although three streaming events were already published. Kafka Connect does not commit an offset for every event: it flushes offsets periodically, every offset.flush.interval.ms (60 seconds in the Debezium image, set by its OFFSET_FLUSH_INTERVAL_MS variable), and on a clean shutdown. If the worker crashed at this moment, it would restart from position 157 and publish the insert, update and delete again. That is the at-least-once guarantee, and it is why every consumer that writes to the new database must be idempotent; see Offsets, Restarts & Exactly-Once.

Now stop Kafka Connect gracefully, insert two rows while it is down, and start it again:

Stop Connect, change data, start Connect
docker compose stop connect

docker compose exec mysql mysql -umysqluser -pmysqlpw inventory -e \
  "INSERT INTO customers (first_name, last_name, email) VALUES ('Sarah', 'Thompson', 'sarah.thompson@example.com');
   INSERT INTO customers (first_name, last_name, email) VALUES ('Kenneth', 'Anderson', 'kenneth.anderson@example.com');"

docker compose start connect

While Connect is down the watcher prints nothing, because nothing is being produced. The rows are safe in the MySQL binlog. The graceful stop committed the latest offset, which you can see by reading my_connect_offsets again:

Offsets after the graceful stop (2026-11-09)
["inventory-connector",{"server":"dbserver1"}]	{"ts_sec":1794214272,"file":"mysql-bin.000003","pos":157}
["inventory-connector",{"server":"dbserver1"}]	{"ts_sec":1794214345,"file":"mysql-bin.000003","pos":1352,"row":1,"server_id":223344,"event":2}

The new offset points into the delete transaction (pos 1352 is the start of that transaction, event 2 and row 1 tell the connector how many events and rows of it were already sent). Only the last offset per key counts.

When Connect is back, the connector finds this offset, skips the snapshot and continues streaming:

Connect log after the restart (2026-11-09, trimmed)
08:55:40,645 INFO   MySQL||lifecycle  Server has the binlog file 'mysql-bin.000003' required by the connector
08:55:41,232 INFO   MySQL||snapshot  A previous offset indicating a completed snapshot has been found.
08:55:41,233 INFO   MySQL||snapshot  Snapshot ended with SnapshotResult [status=SKIPPED, offset=BinlogOffsetContext{... currentBinlogFilename='mysql-bin.000003', currentBinlogPosition=1352, ...}]
08:55:41,292 INFO   MySQL||streaming  Starting streaming
08:55:41,378 INFO   MySQL||binlog  Connected to binlog at mysql:3306, starting at BinlogOffsetContext{... currentBinlogFilename='mysql-bin.000003', currentBinlogPosition=1352, ...}

The watcher then prints the two inserts that happened while Connect was down:

The two events delivered after the restart (real output, 2026-11-09, payloads trimmed)
{"before":null,"after":{"id":1006,"first_name":"Sarah","last_name":"Thompson","email":"sarah.thompson@example.com"},
 "source":{"ts_ms":1794214370000,"snapshot":"false","file":"mysql-bin.000003","pos":1857,"row":0,"thread":18},
 "op":"c","ts_ms":1794214541387}
{"before":null,"after":{"id":1007,"first_name":"Kenneth","last_name":"Anderson","email":"kenneth.anderson@example.com"},
 "source":{"ts_ms":1794214370000,"snapshot":"false","file":"mysql-bin.000003","pos":2208,"row":0,"thread":18},
 "op":"c","ts_ms":1794214541389}

Three things to check, and the same three checks apply after every restart of a production connector:

  1. Nothing was lost. Both rows written while Connect was down arrived.

  2. Nothing was duplicated. The topic now has exactly ten messages (offsets 0 to 9): the eight from step 4 plus the two new inserts. The delete at offset 6 was not sent again, because the graceful stop had committed its offset.

  3. The lag is visible. source.ts_ms is 08:52:50 UTC (the commit in MySQL) and ts_ms is 08:55:41 UTC (when the restarted connector read it): 171 seconds, the time between the commit and the moment Kafka Connect was back and streaming. A consumer of this topic was that far behind the source until the connector caught up, which took milliseconds once it was running.

There is one condition. The connector can only resume if the binlog file that holds its offset still exists. MySQL purges old binlog files after binlog_expire_logs_seconds; if the connector is down for longer than that, it fails on start with an error that the binlog position is no longer available, and needs a new snapshot. Size the log retention of the legacy database for the longest outage you are willing to tolerate. See MySQL purges binlog files used by Debezium and Troubleshooting & Failure Recovery.

sequenceDiagram participant DB as MySQL binlog participant C as Debezium task participant O as my_connect_offsets participant T as customers topic C->>DB: read events after pos 157 C->>T: c 1005, u 1004, d 1004, tombstone Note over C,O: offsets are flushed periodically C->>O: commit pos 1352 on graceful stop Note over C: Connect stopped DB->>DB: two INSERTs committed Note over C: Connect started C->>O: read last offset (pos 1352) C->>DB: reconnect at pos 1352 C->>T: c 1006, c 1007

Step 6: The same lab with PostgreSQL

The PostgreSQL connector works the same way from the outside (a JSON configuration, the same envelope, the same offsets topic) but reads a different log. Instead of acting as a binlog replica, it creates a logical replication slot in the database and receives decoded WAL changes through it. Most migrations target PostgreSQL, and many legacy systems run on it, so it is worth seeing the differences once.

The postgres service is already running. Check that it is ready for logical decoding and look at the data:

Check wal_level and the sample data
docker compose exec postgres psql -U postgres -c "SHOW wal_level;"
docker compose exec postgres psql -U postgres -c "SELECT * FROM inventory.customers;"

wal_level must be logical; the example image sets it. The customers table has the same four rows as in MySQL.

Save the connector configuration as register-postgres.json:

register-postgres.json — Debezium PostgreSQL connector for the inventory schema
{
  "name": "inventory-pg-connector",
  "config": {
    "connector.class": "io.debezium.connector.postgresql.PostgresConnector",
    "tasks.max": "1",
    "database.hostname": "postgres",
    "database.port": "5432",
    "database.user": "postgres",
    "database.password": "postgres",
    "database.dbname": "postgres",
    "topic.prefix": "pgserver1",
    "schema.include.list": "inventory",
    "plugin.name": "pgoutput",
    "slot.name": "debezium_tutorial",
    "publication.name": "dbz_publication"
  }
}

The differences from the MySQL configuration:

  • database.dbname is required: a PostgreSQL connector captures one database. schema.include.list then limits it to the inventory schema.

  • topic.prefix is pgserver1, not dbserver1. Both sources have an inventory.customers table, so the same prefix would make both connectors write to dbserver1.inventory.customers. Every connector in a Connect cluster needs its own prefix.

  • plugin.name is pgoutput, the logical decoding plug-in built into PostgreSQL 10 and later and available on managed services. The documented default is decoderbufs, which needs an extension installed on the server, so set pgoutput explicitly. See plugin.name.

  • slot.name names the replication slot (default debezium). One slot per connector; two connectors must never share a slot.

  • publication.name is the publication that pgoutput reads (default dbz_publication). With the default publication.autocreate.mode=all_tables the connector creates it FOR ALL TABLES and filters with the include lists itself.

  • There is no schema.history.internal.*: PostgreSQL sends the table structure with the logical decoding messages, so the PostgreSQL connector does not need a schema history topic.

  • The postgres superuser is fine for a lab only. A production connector uses a dedicated user with the REPLICATION attribute; see PostgreSQL Connector.

Register it the same way:

Register the PostgreSQL connector and inspect the slot
curl -s -X POST -H "Content-Type:application/json" localhost:8083/connectors/ -d @register-postgres.json | jq .name

curl -s 'localhost:8083/connectors?expand=status' \
  | jq -c 'map_values([.status.connector.state, .status.tasks[0].state])'

docker compose exec postgres psql -U postgres -c \
  "SELECT slot_name, plugin, slot_type, active, confirmed_flush_lsn FROM pg_replication_slots;"
Output on 2026-11-09
"inventory-pg-connector"
{"inventory-pg-connector":["RUNNING","RUNNING"],"inventory-connector":["RUNNING","RUNNING"]}

     slot_name     |  plugin  | slot_type | active | confirmed_flush_lsn
-------------------+----------+-----------+--------+---------------------
 debezium_tutorial | pgoutput | logical   | t      | 0/2B6BC98

The Connect log shows the connector creating the publication and the slot before it takes the snapshot:

Connect log for the PostgreSQL connector (2026-11-09, trimmed)
08:58:46,353 INFO   Postgres||lifecycle  Connector started with no previous offset for partition 'PostgresPartition [sourcePartition={server=pgserver1}]'
08:58:46,369 INFO   Postgres||postgres-connector-task  Creating Publication with statement 'CREATE PUBLICATION dbz_publication FOR ALL TABLES;'
08:58:46,373 INFO   Postgres||postgres-connector-task  Creating replication slot with command CREATE_REPLICATION_SLOT "debezium_tutorial"  LOGICAL pgoutput
08:58:46,425 INFO   Postgres||snapshot  Snapshot step 1 - Preparing
08:58:46,445 INFO   Postgres||snapshot  Read xlogStart at 'LSN{0/2B6BC98}' from transaction '795'
08:58:46,488 INFO   Postgres||snapshot  Snapshot step 7 - Snapshotting data
08:58:46,539 INFO   Postgres||snapshot  Snapshot ended with SnapshotResult [status=COMPLETED, ...]

Unlike the MySQL connector, which took a global read lock in step 3 of its snapshot, the PostgreSQL connector takes no table locks by default (snapshot.locking.mode=none; step 3 still appears in the log but acquires nothing). It reads the tables in a repeatable-read transaction that uses the snapshot exported when the slot was created, so the snapshot and the slot start at the same LSN (0/2B6BC98).

Run the same changes as in MySQL. The PostgreSQL sample has no addresses table, so customer 1004 can be deleted directly:

Insert, update and delete in PostgreSQL
docker compose exec postgres psql -U postgres -c \
  "INSERT INTO inventory.customers (first_name, last_name, email) VALUES ('Lena', 'Okafor', 'lena.okafor@example.com');"
docker compose exec postgres psql -U postgres -c \
  "UPDATE inventory.customers SET first_name='Anne Marie' WHERE id=1004;"
docker compose exec postgres psql -U postgres -c \
  "DELETE FROM inventory.customers WHERE id=1004;"
pgserver1.inventory.customers after the changes (real output, 2026-11-09, summarised with jq)
0 {"op":"r","after":{"id":1001,...},"src":{"lsn":45530264,"txId":795,"snapshot":"first"}}
1 {"op":"r","after":{"id":1002,...},"src":{"lsn":45530264,"txId":795,"snapshot":"true"}}
2 {"op":"r","after":{"id":1003,...},"src":{"lsn":45530264,"txId":795,"snapshot":"true"}}
3 {"op":"r","after":{"id":1004,...},"src":{"lsn":45530264,"txId":795,"snapshot":"last_in_data_collection"}}
4 {"op":"c","before":null,"after":{"id":1005,"first_name":"Lena",...},"src":{"lsn":45571064,"txId":796,"snapshot":"false"}}
5 {"op":"u","before":{"id":1004,"first_name":"Anne",...},"after":{"id":1004,"first_name":"Anne Marie",...},"src":{"lsn":45571680,"txId":797}}
6 {"op":"d","before":{"id":1004,"first_name":"Anne Marie",...},"after":null,"src":{"lsn":45571888,"txId":798}}
7 tombstone

The envelope is identical; only source differs. A PostgreSQL event carries the PostgreSQL position instead of a binlog file and position:

source block of the PostgreSQL update event (real output, 2026-11-09)
{
  "version": "3.7.1.Final", "connector": "postgresql", "name": "pgserver1",
  "ts_ms": 1794214759926, "snapshot": "false", "db": "postgres",
  "sequence": "[\"45571680\",\"45571680\"]",
  "schema": "inventory", "table": "customers",
  "txId": 797, "lsn": 45571680, "xmin": null,
  "origin": null, "origin_lsn": null,
  "ts_us": 1794214759926160, "ts_ns": 1794214759926160000
}

lsn is the WAL position (45571680 is 0/2B75E60 in PostgreSQL notation) and txId the transaction ID. Every snapshot event has the same LSN and transaction, the one recorded when the slot was created, which mirrors the single binlog position of the MySQL snapshot.

REPLICA IDENTITY decides what before contains

The update above has a full before image. That is only because the example-postgres image sets REPLICA IDENTITY FULL on its tables. A normal PostgreSQL table uses REPLICA IDENTITY DEFAULT, which writes only the primary key of the old row to the WAL. To see the difference, switch the table to the default and repeat an update and a delete:

Switch to REPLICA IDENTITY DEFAULT, change rows, switch back
docker compose exec postgres psql -U postgres -c "ALTER TABLE inventory.customers REPLICA IDENTITY DEFAULT;"
docker compose exec postgres psql -U postgres -c "UPDATE inventory.customers SET last_name='Bailey-Ross' WHERE id=1002;"
docker compose exec postgres psql -U postgres -c "DELETE FROM inventory.customers WHERE id=1005;"
docker compose exec postgres psql -U postgres -c "ALTER TABLE inventory.customers REPLICA IDENTITY FULL;"
Events with REPLICA IDENTITY DEFAULT (real output, 2026-11-09)
9  {"before":null,"after":{"id":1002,"first_name":"George","last_name":"Bailey-Ross","email":"gbailey@foobar.com"},"op":"u"}
10 {"before":{"id":1005,"first_name":"","last_name":"","email":""},"after":null,"op":"d"}
11 tombstone

The excerpt starts at offset 9; the record at offset 8 is not shown.

With DEFAULT, the update has "before": null, and the delete has a before image that contains only the real primary key: the other columns are NOT NULL in the schema, so the connector fills them with empty strings. A consumer that reads before.email of a delete gets "", not the deleted customer’s address. For a migration this matters in three places:

  • an anti-corruption layer that needs the old value to translate a change (for example to find the previous status of an order) cannot get it;

  • audit or reconciliation logic that compares before and after sees nothing to compare;

  • a sink that needs the old value of a non-key column to find the target row cannot find it.

Decide per table whether you need full before images, and set REPLICA IDENTITY FULL on the legacy tables that need it (it increases WAL volume). The PostgreSQL connector can set it for you with replica.identity.autoset.values. See PostgreSQL Connector and Data Types & Precision for the related TOAST column behaviour.

Restart and resume with a replication slot

Repeat the restart test. Stop Connect, insert a row, look at the slot, and start Connect again:

Stop Connect and inspect the slot
docker compose stop connect
docker compose exec postgres psql -U postgres -c \
  "INSERT INTO inventory.customers (first_name, last_name, email) VALUES ('Sarah', 'Thompson', 'sarah.thompson@example.com');"
docker compose exec postgres psql -U postgres -c \
  "SELECT slot_name, active, confirmed_flush_lsn, pg_current_wal_lsn() FROM pg_replication_slots;"
docker compose start connect
Slot while Connect was stopped (2026-11-09)
     slot_name     | active | confirmed_flush_lsn | pg_current_wal_lsn
-------------------+--------+---------------------+--------------------
 debezium_tutorial | f      | 0/2B781B8           | 0/2B785D0

The slot is inactive, and its confirmed_flush_lsn stays behind the current WAL position. This is the PostgreSQL counterpart of the binlog retention problem, and more dangerous: an inactive slot makes PostgreSQL keep every WAL segment after confirmed_flush_lsn. A connector that stays stopped for days on a busy legacy database can fill the disk. Monitor slot lag (pg_current_wal_lsn() minus confirmed_flush_lsn) and cap it with PostgreSQL’s max_slot_wal_keep_size; see PostgreSQL Connector.

On start, the connector reads its offset from my_connect_offsets, checks the slot and asks PostgreSQL to continue from there:

Connect log after the restart (2026-11-09, trimmed)
09:08:13,743 INFO   Postgres||lifecycle  Found previous partition offset PostgresPartition [sourcePartition={server=pgserver1}]: {lsn_proc=45580784, lsn_events_processed=1, messageType=DELETE, lsn_commit=45580728, lsn=45580784, txId=804, ts_usec=1794214792416671}
09:08:13,825 INFO   Postgres||lifecycle  Obtained valid replication slot ReplicationSlot [active=false, latestFlushedLsn=LSN{0/2B781B8}, catalogXmin=804]
09:08:13,975 INFO   Postgres||snapshot  A previous offset indicating a completed snapshot has been found.
09:08:14,452 INFO   Postgres||streaming  Starting streaming
09:08:14,452 INFO   Postgres||streaming  Retrieved latest position from stored offset 'LSN{0/2B781F0}'
09:08:14,756 INFO   Postgres||streaming  WAL resume position 'LSN{0/2B78260}' discovered
09:08:15,030 INFO   Postgres||streaming  Processing messages
09:08:15,479 INFO   Postgres||lifecycle  1 records sent during previous 00:00:22.08, last recorded offset of {server=pgserver1} partition is {lsn_proc=45581472, ..., messageType=INSERT, txId=806, ...}
The event delivered after the restart (real output, 2026-11-09)
{"after":{"id":1006,"first_name":"Sarah","last_name":"Thompson","email":"sarah.thompson@example.com"},
 "op":"c","lsn":45581472,"src_ts":1794214812964,"ts_ms":1794215295088}

The insert committed at 09:00:12 UTC was delivered at 09:08:15 UTC when the connector came back, at topic offset 12, after the tombstone at offset 11. The log reports exactly one record sent after the restart, and that record is the insert made while Connect was stopped: nothing lost, nothing repeated. The slot is active again and its confirmed_flush_lsn advances as the connector commits offsets.

Step 7: Clean up

Deleting a connector removes its configuration from Kafka Connect, but not what it created in the source database. For PostgreSQL that means the replication slot and the publication. A forgotten slot keeps WAL forever, so drop both:

Delete the PostgreSQL connector, then its slot and publication
curl -s -o /dev/null -w '%{http_code}\n' -X DELETE localhost:8083/connectors/inventory-pg-connector
# 204

docker compose exec postgres psql -U postgres -c "SELECT slot_name, active FROM pg_replication_slots;"
#      slot_name     | active
# -------------------+--------
#  debezium_tutorial | f

docker compose exec postgres psql -U postgres -c "SELECT pg_drop_replication_slot('debezium_tutorial');"
docker compose exec postgres psql -U postgres -c "DROP PUBLICATION dbz_publication;"

slot.drop.on.stop=true makes the connector drop its slot on every graceful stop. That is convenient in tests but wrong for a migration pipeline: after a restart the connector would have to take a new snapshot, because the changes between the stop and the start are gone with the slot.

The MySQL connector leaves nothing in the database, so deleting it is enough. Then stop and remove the whole stack, including its volumes:

Remove the stack
curl -s -X DELETE localhost:8083/connectors/inventory-connector
docker compose down -v
docker ps -a --filter name=dbz-tutorial

The last command must print only the header line. Because Kafka keeps its data inside the container and the Compose file defines no named volumes, down -v removes all topics, offsets and connector configurations; the next docker compose up -d starts from nothing and every connector takes a new snapshot.

What can go wrong

Symptom Likely cause Fix

curl: (7) Failed to connect to localhost port 8083

Kafka Connect is still scanning plugins, or the container was killed.

Wait and retry. Check docker compose ps; Exited (137) means the out-of-memory killer stopped it. Give Docker more memory or keep the HEAP_OPTS cap.

Task state FAILED with Communications link failure or Connection refused

database.hostname is localhost or a host port.

Use the Compose service name and the container port (mysql, 3306; postgres, 5432).

Registration returns 409 Conflict

A connector with that name already exists.

Update it with PUT /connectors/<name>/config, or delete it first.

Two connectors write to the same topics

Same topic.prefix on two connectors.

Give each connector its own prefix.

A host client hangs or fails on kafka:9092

The client got the internal advertised listener.

Connect from the host with localhost:9092 (the EXTERNAL listener), and from containers with kafka:9092.

PostgreSQL connector fails with a decoderbufs error

plugin.name was left at its default.

Set plugin.name to pgoutput.

PostgreSQL disk grows while Connect is down

The inactive replication slot retains WAL.

Restart the connector, or drop the slot if the connector is gone for good.

After a restart, events already seen arrive again

The worker stopped without committing its last offset (crash or kill).

Expected under at-least-once delivery. Make consumers idempotent.

From the tutorial to the Bookshop migration

Everything in this lab carries over to the legacy Bookshop pipeline; only the scale and the source change:

Tutorial Bookshop migration Covered in

inventory-connector, topic.prefix=dbserver1

bookshop-oracle-source, topic.prefix=legacy, topics legacy.BOOKSHOP.BOOK and so on

Oracle Connector

schemahistory.inventory

legacy.schema-history

Handling Schema Changes

watch-topic and kcat

The JDBC sink bookshop-pg-mirror-sink and the Spring Boot consumer group bookshop-legacy-sync

JDBC Sink Connector, Listening to Events in Applications

Four-row snapshot

A multi-gigabyte snapshot of BOOK, CUSTOMER, ORDERS and ORDER_LINE

Initial Snapshots

One Connect container, one Kafka node

A replicated Kafka cluster and a Connect cluster, often on Kubernetes

Installing Debezium, Running on Kubernetes

Restart test by hand

Automated restart and failure tests

Testing CDC Pipelines

The Debezium debezium-examples tutorial directory has Compose files for the same tutorial with MongoDB, SQL Server, Oracle and other databases. For Kafka Connect itself (workers, converters, the REST API), see Kafka Connect.

References

The Compose stack, both connector configurations and every command on this page were run with Docker on 2026-11-09 against the 3.7.1.Final images; the event and log output is real, trimmed for width, with timestamps shortened.