Kafka Connect and Schema Registry
Move data into and out of Kafka without custom code using Kafka Connect, and keep producers and consumers compatible with a schema registry.
Advanced · about 5 hours · difficulty 4/5
Learn first: Apache Kafka Fundamentals, Avro and Schema Evolution, Managed Ingestion and Change Data Capture
Writing a custom producer for every database and a custom consumer for every sink is wasteful. The Kafka ecosystem provides standard pieces for both.
Kafka Connect
- A framework for source connectors (database, files, Debezium CDC into Kafka) and sink connectors (Kafka into S3, BigQuery, Snowflake, Elasticsearch, Postgres).
- Runs as a cluster of workers configured through JSON and a REST API.
- Single message transforms (SMTs) do light changes like renaming fields or routing topics.
- Handles offsets, retries and scaling for you.
Schema Registry
- Stores Avro, Protobuf or JSON Schema definitions per topic.
- Producers register schemas; messages carry only a small schema ID.
- Compatibility modes (backward, forward, full) reject breaking changes at produce time, stopping a bad deploy from breaking every consumer. This connects directly to what you learned about schema evolution.
A typical CDC to lake pipeline
Postgres, then Debezium source connector, then Kafka topics (one per table), then an S3 sink connector writing Parquet, then a lakehouse table updated by a merge job. Or a streaming engine consuming the topics directly.
Kafka Streams and ksqlDB
For lightweight processing inside the Kafka ecosystem, Kafka Streams (a Java library) and ksqlDB (SQL over streams) exist. Know what they are; Spark or Flink are more common in data engineering roles.
Pitfalls
- No schema registry, so one producer changing a field type breaks consumers silently.
- Ignoring dead letter queues and losing bad records.
You are ready to move on when you can run a Debezium source and a file or S3 sink connector through Kafka Connect with Avro and Schema Registry, and show a compatible schema change succeeding while an incompatible one is rejected.
Key concepts
- Source and sink connectors
- Connect workers and REST API
- Single message transforms
- Schema Registry
- Compatibility modes
- Dead letter queues
- Kafka Streams and ksqlDB
Mini project
With Docker Compose, run Postgres, Kafka, Kafka Connect with Debezium, and Schema Registry. Stream changes from an orders table into Kafka as Avro, sink them to files or MinIO, then attempt a breaking schema change and capture the rejection.
Check yourself
Why does a schema registry reduce message size and also prevent outages?
Free resources
- Apache Kafka documentation (Connect) (Apache Kafka)
- Confluent documentation (Confluent)
- Debezium documentation (Debezium)