Video in progress
What is Kafka Connect, and when do you use it instead of your own producer/consumer code?
Kafka Connect is a ready-made framework for moving data between Kafka and external systems (DBs, S3, Elasticsearch): a source connector writes to Kafka, a sink connector reads from Kafka. If there's no business logic and you only need "copy from A to B", configuring a connector is cheaper than writing code.
📖 Answer
Say you need to push everything from the orders topic into Elasticsearch for search, or into S3 for an archive. If you write it yourself, you need a consumer, batching, retries, offset management, scaling, monitoring. In Connect it's one JSON:
{
"name": "orders-to-s3",
"config": {
"connector.class": "io.confluent.connect.s3.S3SinkConnector",
"topics": "orders",
"tasks.max": "4",
"s3.bucket.name": "orders-archive",
"flush.size": "10000",
"errors.tolerance": "all",
"errors.deadletterqueue.topic.name": "orders-s3-dlq"
}
}
Connect workers run as a cluster in distributed mode and share the tasks among themselves; the configuration, offsets and state are stored in Kafka's internal topics. For light transformations there are SMTs (single message transforms): dropping a field, renaming the topic.
When I'd write my own code instead of using Connect:
- each message involves a business rule, a call to another service or complex validation;
- there's no good connector for the system you need;
- nobody on the team can run a Connect cluster, which is separate infrastructure too.
The most common in practice are Debezium (DB changes into Kafka) and sink connectors (from Kafka to a DWH, search, object storage).
Sign up to mark studied questions and save your progress.