The Kafka Ecosystem: Kafka Connect and Kafka Streams
Understand the broader Kafka ecosystem, integrate databases via Kafka Connect CDC, and build stream processing topologies with Kafka Streams.
Building modern event-driven architectures involves more than writing custom @KafkaListener and KafkaTemplate code. In enterprise systems, Kafka acts as the central data nervous system, streaming events between databases, microservices, analytical data lakes, and search indexes.
Writing custom producer and consumer code for every database table, search index, and aggregation pipeline leads to redundant code, brittle error handling, and high maintenance costs.
To solve this, the Kafka platform provides two native ecosystem frameworks: Kafka Connect for declarative data integration, and Kafka Streams for real-time stream processing.
01Kafka Connect: Declarative data integration
Kafka Connect is a distributed, scalable framework for streaming data between Apache Kafka and external systems. Instead of writing custom applications, engineers configure declarative JSON connectors.
Kafka Connect divides integration into two connector types:
- Source Connectors: Ingest data from external systems into Kafka topics (e.g., streaming relational database tables, MongoDB change streams, or Salesforce events).
- Sink Connectors: Export data from Kafka topics into downstream destination systems (e.g., indexing records into Elasticsearch, loading data into Snowflake, or writing Parquet files to Amazon S3).
Change Data Capture (CDC) with Debezium
The most popular source connector in modern microservices is Debezium. Debezium performs Change Data Capture (CDC) by tailing the transaction log of relational databases (such as PostgreSQL Write-Ahead Logs or MySQL binary logs).
Whenever an application executes an INSERT, UPDATE, or DELETE:
- Debezium captures the change event from the database transaction log with sub-second latency.
- It converts the row before-and-after state into an Avro or JSON event.
- It publishes the event to a dedicated Kafka topic (e.g.,
dbserver1.inventory.customers). - The primary application database experiences minimal overhead because no SQL polling (
SELECT * FROM table WHERE updated_at > ?) is performed.
Sample Kafka Connect configuration
Connectors are deployed and managed via the Kafka Connect REST API:
{
"name": "postgres-order-source",
"config": {
"connector.class": "io.debezium.connector.postgresql.PostgresConnector",
"tasks.max": "1",
"plugin.name": "pgoutput",
"database.hostname": "postgres.internal",
"database.port": "5432",
"database.user": "debezium",
"database.password": "secret",
"database.dbname": "orders_db",
"database.server.name": "fulfillment",
"table.include.list": "public.orders,public.order_items",
"topic.prefix": "cdc",
"key.converter": "io.confluent.kafka.serializers.KafkaAvroSerializer",
"value.converter": "io.confluent.kafka.serializers.KafkaAvroSerializer",
"key.converter.schema.registry.url": "http://schema-registry:8081",
"value.converter.schema.registry.url": "http://schema-registry:8081"
}
}Loading the rest of the lesson…