Apache Kafka — Event Streaming from Basics to a Platform Service›12 · Kafka Connect, CDC and stream processing

Lesson 12 of 17 · The ecosystem

Kafka Connect, CDC and stream processing

Moving data in and out of Kafka without writing code, and processing it as it flows. Kafka Connect workers, connectors and tasks, converters and single message transforms, error handling with a dead-letter queue; change data capture with Debezium (reading a database's change log, the event format, the outbox router); and stream processing with Kafka Streams and Apache Flink: streams versus tables, windows, state, and how to choose.

Practitioner
Key wordsKafka Connectsource connectorsink connectorworkertaskdistributed modeconnector REST APISMTsingle message transformconverterDebeziumchange data captureCDCbinlogWALoutbox event routerKafka StreamsKStreamKTablewindowingstate storeApache FlinkksqlDBstream processing

Kafka Connect: integration without code

Most data in Kafka comes from somewhere (databases, files, SaaS APIs) and goes to somewhere (warehouses, search, object storage). Kafka Connect is Kafka's framework for this: you configure a connector; Connect runs it reliably.

 PostgreSQL ──► [ source connector ] ──► Kafka topics ──► [ sink connector ] ──► S3 / Elasticsearch / Snowflake
                         Kafka Connect cluster (workers, running tasks)
Term Meaning
Worker A Connect process. Run several in distributed mode for scale and failover
Connector A configured integration, such as "Postgres orders DB to Kafka"
Task A unit of work; tasks.max sets how many run in parallel
Converter Turns records into bytes: JSON, Avro or Protobuf with a schema registry
SMT Single message transform: small per-record changes (rename a field, drop PII, route to another topic)

Connect stores its configuration, offsets and status in compacted Kafka topics, so workers are stateless and replaceable. You manage it through a REST API (or, on Kubernetes, KafkaConnect and KafkaConnector resources in Strimzi):

$ curl -s -X POST -H "Content-Type: application/json" http://connect:8083/connectors -d '{
    "name": "orders-to-s3",
    "config": {
      "connector.class": "io.confluent.connect.s3.S3SinkConnector",
      "topics": "orders",
      "tasks.max": "3",
      "s3.bucket.name": "events-archive",
      "errors.tolerance": "all",
      "errors.deadletterqueue.topic.name": "orders.connect.dlq"
    }}'
$ curl -s http://connect:8083/connectors/orders-to-s3/status

Connectors are code you run

Connector plugins come from many vendors with different licences and quality. Pin versions, build them into your Connect image, and test upgrades. A failed task does not fix itself: alert on task state FAILED.

Change data capture with Debezium

Change data capture (CDC) turns every database change into an event. Debezium is the standard open-source CDC platform, implemented as Kafka Connect source connectors for PostgreSQL, MySQL, SQL Server, Oracle, MongoDB and more.

It reads the database's own change log, not the tables:

Database Debezium reads
PostgreSQL The write-ahead log (WAL), through logical replication
MySQL / MariaDB The binlog
SQL Server Its CDC tables
MongoDB The change stream

So it sees every committed insert, update and delete, in order, with little load on the database, and without changing the application.

A change event carries the row before and after, plus metadata:

{
  "before": { "id": 123, "status": "placed" },
  "after":  { "id": 123, "status": "paid" },
  "source": { "db": "shop", "table": "orders", "lsn": 24023128 },
  "op": "u",
  "ts_ms": 1762596123000
}

op is c (create), u (update), d (delete) or r (read, during the initial snapshot). Each table goes to its own topic, keyed by primary key, which suits compaction.

Outbox with Debezium: in lesson 10 the service wrote events into an outbox table. Debezium's outbox event router SMT reads that table and publishes each row to the right topic, with the right key and payload. That gives reliable "database change plus event" with no dual write.

CDC is like a security camera on the shop's till roll. Instead of asking the cashier every hour "what did you sell?", you watch the till roll as it prints, and copy every line the moment it appears. You see every sale, in order, and the cashier doesn't have to do anything extra.

CDC watch points:

  • The initial snapshot of a large table can take hours; plan it.
  • PostgreSQL keeps WAL until Debezium confirms it: a stopped connector makes the database disk fill up. Alert on replication slot lag.
  • Schema changes in the database flow into events: combine CDC with a schema registry and compatibility rules.

Stream processing

Consumers that just react to each event are enough for many cases. When you need joins, aggregations, windows or state, use a stream processor.

Streams and tables

Stream (KStream) Table (KTable)
Represents Every event: "order 123 placed", "order 123 paid" The latest state per key: "order 123 is paid"
Kafka storage Normal topic Compacted topic
Example Clicks, payments Current customer profile

A stream can be turned into a table (aggregate by key), and a table emits a stream of its changes. This stream–table duality is at the heart of Kafka processing.

Windows and time

Aggregations over unbounded streams need windows: tumbling (fixed, non-overlapping, such as every 5 minutes), hopping (overlapping), sliding, and session windows (activity separated by gaps). Processors work in event time (when it happened) rather than processing time, and must handle late events with a grace period.

Kafka Streams Apache Flink
What it is A Java library inside your application A separate cluster (job manager + task managers)
Sources and sinks Kafka to Kafka Kafka plus many others (files, databases, cloud services)
State Local RocksDB, backed up to compacted changelog topics Large managed state with checkpoints to object storage
Scaling Run more instances (up to the partition count) Set job parallelism; the cluster schedules it
Exactly-once processing.guarantee=exactly_once_v2 Checkpoints + transactional sinks
Interfaces Java DSL Java, Python, SQL
Best for Service-level enrichment, aggregation, routing Big, complex, multi-source pipelines and analytics

ksqlDB offers SQL over Kafka Streams; many teams now use Flink SQL for that role.

End to end: from one event to a point on a chart

How does a single order end up as a bar on a live revenue dashboard? Follow it through the pipeline from lesson 2.

1 · Event shop.orders.v1 2 · Aggregate Flink, 1-min window 3 · Store ClickHouse table 4 · Plot Grafana time series {   "order": "A-17",   "region": "EU",   "amount": 42.50,   "ts": "10:01:12" } key A-17 → partition 2 sent by the checkout service 10:00 10:01 EU · 10:01 → 3 orders revenue 142.50 emitted when the minute closes minute region revenue 09:59 EU 1,870 10:00 US 2,410 10:00 EU 1,980 10:01EU142.50 one row per minute and region 09:56 10:01 SQL query per panel refreshed every 5 s each event is counted into its minute → one row per minute and region → one bar per row
One event is counted into its one-minute window; each window becomes a row in an analytics table; each row becomes a bar on the chart.

1. The event. The checkout service produces a record to shop.orders.v1 with the order ID as key:

{ "order": "A-17", "region": "EU", "amount": 42.50, "ts": "2026-11-08 10:01:12" }

2. Aggregate. A Flink SQL job reads the topic, groups events into one-minute tumbling windows per region, and writes one result per window to a new topic. The watermark tells Flink how long to wait for late events before it closes a minute:

CREATE TABLE orders (
  `order` STRING, region STRING, amount DECIMAL(10, 2), ts TIMESTAMP(3),
  WATERMARK FOR ts AS ts - INTERVAL '5' SECOND
) WITH (
  'connector' = 'kafka', 'topic' = 'shop.orders.v1',
  'properties.bootstrap.servers' = 'kafka:9092', 'properties.group.id' = 'orders-per-minute',
  'scan.startup.mode' = 'earliest-offset', 'format' = 'json'
);

CREATE TABLE orders_per_minute (
  window_start TIMESTAMP(3), region STRING, orders BIGINT, revenue DECIMAL(12, 2)
) WITH (
  'connector' = 'kafka', 'topic' = 'shop.orders.per-minute.v1',
  'properties.bootstrap.servers' = 'kafka:9092', 'format' = 'json'
);

INSERT INTO orders_per_minute
SELECT window_start, region, COUNT(*), SUM(amount)
FROM TABLE(TUMBLE(TABLE orders, DESCRIPTOR(ts), INTERVAL '1' MINUTE))
GROUP BY window_start, window_end, region;

3. Store. A sink connector (here the ClickHouse sink for Kafka Connect) copies shop.orders.per-minute.v1 into a table that is fast for time-range queries:

CREATE TABLE orders_per_minute (
  window_start DateTime,
  region       LowCardinality(String),
  orders       UInt64,
  revenue      Decimal(12, 2)
) ENGINE = MergeTree
ORDER BY (region, window_start);

4. Plot. A Grafana time-series panel queries the table for the time range on screen and refreshes every few seconds. $__timeFilter is a Grafana macro that becomes the dashboard's time range:

SELECT window_start AS time, region, revenue
FROM orders_per_minute
WHERE $__timeFilter(window_start)
ORDER BY time

Each row is one point (or bar) per region per minute. With a 1-minute window and a 5-second watermark, the newest bar appears a few seconds after its minute ends: that delay is the price of a correct count.

Choice Simpler alternative When the simpler one is enough
Flink computes the aggregates Load raw events into ClickHouse (its Kafka table engine or a sink) and aggregate at query time or with a materialized view Moderate volume; no joins across topics
Separate analytics store Grafana reading a PostgreSQL table Small data, few dashboards
Tumbling 1-minute windows Hopping or session windows Rolling averages, user sessions

Who owns what

The producing team owns shop.orders.v1 and its schema. The analytics team owns the Flink job, the derived topic and the dashboard. Neither has to ask the other before changing their side, as long as the schema stays compatible (lesson 11).

Try it: CDC end to end

  1. Add PostgreSQL (with wal_level=logical) and a Kafka Connect worker with the Debezium PostgreSQL connector to the lab network.
  2. Create a connector for a table orders, then insert, update and delete rows. Consume the topic and read before, after and op.
  3. Stop the connector for a while, make changes, and start it again: confirm nothing was missed.
  4. Add an outbox table and the outbox event router SMT; publish a business event by inserting a row in the same transaction as an order.

Going deeper

  • Size Connect like any service: CPU for converters, memory for buffers, and enough tasks for the partitions involved.
  • Use separate Connect clusters for teams or critical pipelines, so one bad connector cannot starve the others.
  • Stream processors repartition data when you change the key, creating internal topics. Count them in partition and storage budgets.

Recap

  • Kafka Connect runs source and sink connectors as tasks on stateless workers, configured by REST or Kubernetes resources.
  • Debezium captures database changes from the transaction log: every change, in order; it powers the outbox pattern.
  • Streams are events; tables are latest state per key, on compacted topics.
  • Kafka Streams is a library for Kafka-to-Kafka processing; Flink is a cluster for large, multi-source jobs and SQL.
  • End to end: collect → Kafka → aggregate (Flink) → sink to an analytics store → dashboard; dashboards query the store, not Kafka.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.