The one-line mental model
Kafka Connect is a framework where connectors define what data moves, tasks do the moving, workers host the tasks, converters handle serialization, and single message transforms reshape records in flight before they ever reach a consumer.
You will be able to choose distributed versus standalone mode, configure a source and a sink connector with correct task counts, apply transforms safely, and wire a dead letter queue so poison messages never stall the pipeline.
Prerequisites
- !Kafka topics, partitions and consumer groups
- !Basic REST API familiarity for the Connect control plane
What You'll Learn
- 1Explain the worker, connector, task and converter relationship
- 2Configure JDBC source and S3 or Elasticsearch sink connectors
- 3Chain single message transforms without breaking schemas
- 4Design dead letter queues and tune worker throughput
Workers, connectors, tasks and converters
A Connect deployment is a cluster of worker processes, each running on a JVM and each able to host many connectors. A connector is a configuration object that declares what should happen: poll a database, write to Elasticsearch, mirror a topic. The runtime splits that declaration into one or more tasks, which are the units of parallelism. A JDBC source connector with three tasks might assign table A to task 0, table B to task 1, and table C to task 2. The framework handles offset tracking, rebalancing when workers join or leave, and fault tolerance, so connector authors focus on the read and write logic rather than on distribution.
Converters sit at the boundary between Kafka and the connector. They decide how records are serialized to and from bytes on the wire and how schemas travel with them. JSON is human-readable and fine for prototypes. Avro with a schema registry is compact, supports evolution, and is the default recommendation for production pipelines where producers and consumers deploy independently. Protobuf offers a middle ground with strong typing and a large tooling ecosystem. Choosing the wrong converter is a subtle production bug: a JSON converter without schema support forces downstream consumers to guess field types, and that guess fails the first time a field changes from an integer to a string.
bootstrap.servers=kafka1:9092,kafka2:9092,kafka3:9092
group.id=connect-cluster
key.converter=io.confluent.connect.avro.AvroConverter
value.converter=io.confluent.connect.avro.AvroConverter
value.converter.schema.registry.url=http://schema-registry:8081
offset.storage.topic=connect-offsets
config.storage.topic=connect-configs
status.storage.topic=connect-status
offset.flush.interval.ms=10000
In distributed mode the offset, config and status topics live inside Kafka itself, which is what gives the cluster its resilience: any worker can pick up any task after a rebalance. In standalone mode those live in local JSON files, which is convenient for development but means a lost worker means lost state.
Source connectors: capturing change from databases
A source connector polls an external system and writes the results to Kafka topics. The JDBC source connector is the most common, and its configuration encodes two decisions that matter: how to identify new rows, and how often to look. Incrementing mode tracks a monotonically increasing column such as an auto-incremented id, which is fast and simple but misses updates to existing rows. Timestamp mode tracks an updated_at column, which catches updates but requires that column to be indexed and reliably maintained. Timestamp plus incrementing combines both and is the safest default when the source schema allows it.
{
"name": "postgres-source",
"config": {
"connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector",
"tasks.max": "3",
"connection.url": "jdbc:postgresql://postgres:5432/orders",
"connection.user": "connect_reader",
"connection.password": "${file:/opt/kafka/secrets/db.properties:password}",
"topic.prefix": "db-",
"table.whitelist": "orders,users,payments",
"mode": "timestamp+incrementing",
"incrementing.column.name": "id",
"timestamp.column.name": "updated_at",
"poll.interval.ms": "1000",
"validate.non.null": "true"
}
}
The task count should never exceed the number of tables being captured, because excess tasks sit idle after the framework assigns zero tables to them. Each task opens its own JDBC connection, so three tasks mean three connections to the source database, and that number should be budgeted alongside the application's own connection pool. For change data capture that must capture deletes, the Debezium connector replaces polling with log reading on the database's write-ahead log, which eliminates the polling lag entirely and is the right answer when the question mentions deletes or sub-second latency.
Sink connectors: writing out to search, lakes and caches
A sink connector consumes topics and writes to an external system. The Elasticsearch sink upserts documents keyed by the record key, which means replaying a partition produces the same final state rather than duplicates. The S3 sink is different in character: it buffers records into files, rolls those files on size or time, and writes them into a partitioned path structure that analytics engines can query directly. That buffering behavior is the source of most S3 sink surprises, because a file that has not yet rolled is not yet visible to downstream readers.
{
"name": "s3-sink",
"config": {
"connector.class": "io.confluent.connect.s3.S3SinkConnector",
"tasks.max": "3",
"topics": "db-orders",
"s3.bucket.name": "acme-data-lake",
"s3.region": "us-east-1",
"storage.class": "io.confluent.connect.s3.storage.S3Storage",
"format.class": "io.confluent.connect.s3.format.parquet.ParquetFormat",
"partitioner.class": "io.confluent.connect.storage.partitioner.TimeBasedPartitioner",
"path.format": "'year'=YYYY/'month'=MM/'day'=dd",
"locale": "en-US",
"timezone": "UTC",
"flush.size": "50000",
"rotate.interval.ms": "300000",
"rotate.schedule.interval.ms": "900000"
}
}
flush.size is the primary knob. Too small and you produce thousands of tiny files that make Athena and Spark queries slow and expensive. Too large and a pipeline failure delays visibility for hours. rotate.interval.ms and rotate.schedule.interval.ms provide time-based safety nets so that low-traffic topics still produce files on a predictable cadence. The combination of size-based and time-based rotation gives you both throughput under load and freshness under quiet.
Single message transforms
Single message transforms, or SMTs, are lightweight in-process functions applied to each record before it leaves the connector or before it reaches the sink. They chain in the order declared, and each one receives the output of the previous. Built-in transforms cover the most common shapes: InsertField adds a constant or timestamp field, ReplaceField renames or removes fields, MaskField redacts sensitive values such as emails or card numbers, Cast converts types, and TimestampRouter rewrites the target topic name to include a date partition.
{
"name": "orders-pipeline",
"config": {
"connector.class": "io.confluent.connect.jdbc.JdbcSourceConnector",
"transforms": "addSource,maskEmail,renameId",
"transforms.addSource.type": "org.apache.kafka.connect.transforms.InsertField$Value",
"transforms.addSource.static.field": "source_system",
"transforms.addSource.static.value": "postgres-orders",
"transforms.maskEmail.type": "org.apache.kafka.connect.transforms.MaskField$Value",
"transforms.maskEmail.fields": "email",
"transforms.maskEmail.replacement": "****@redacted.com",
"transforms.renameId.type": "org.apache.kafka.connect.transforms.ReplaceField$Value",
"transforms.renameId.renames": "id:order_id,user_id:customer_id"
}
}
Two cautions apply to every SMT chain. First, transforms run inside the worker process, so an expensive transform becomes a throughput bottleneck with no automatic backpressure. Second, schema-changing transforms can break consumers that were compiled against the original schema, which is why field renames belong in a schema registry compatibility check rather than in a last-minute connector edit. For anything more complex than a rename or a mask, write a custom transform, test it against the exact schema version in production, and version it alongside your connector configs in source control.
Dead letter queues and error handling
Every pipeline eventually encounters a record it cannot process: a malformed JSON payload, a schema violation, a downstream timeout. Without a strategy, that record either fails the task or is silently dropped. A dead letter queue gives you a third option: capture the failed record along with the error metadata, continue processing, and handle the quarantine asynchronously.
{
"name": "orders-es-sink",
"config": {
"connector.class": "io.confluent.connect.elasticsearch.ElasticsearchSinkConnector",
"topics": "db-orders",
"connection.url": "http://elasticsearch:9200",
"errors.tolerance": "all",
"errors.deadletterqueue.topic.name": "orders-dlq",
"errors.deadletterqueue.topic.replication.factor": "3",
"errors.deadletterqueue.headers.add": "true",
"errors.log.enable": "true",
"errors.log.include.messages": "false",
"errors.context.headers.enable": "true"
}
}
With errors.tolerance set to all, every failing record is routed to the DLQ and the task keeps running. Set to none, the task fails on the first error, which is appropriate for financial pipelines where silent data loss is unacceptable. The headers added by errors.context.headers.enable carry the original topic, partition, offset, connector name and the Java exception class, which is usually enough for a consumer to either repair the record or alert the right owner. A DLQ without a consumer is just a slower form of data loss, so assign a processor that either fixes and re-publishes or pages a human, and alarm on the DLQ lag metric so growth does not go unnoticed.
Performance and operational tuning
Throughput tuning starts with task count and batching. More tasks mean more parallelism, but only up to the number of partitions on the source topics and the capacity of the external system. Sink connectors expose batch size and linger settings that trade latency for throughput; source connectors expose poll intervals and batch sizes. Worker-level settings such as offset.flush.interval.ms control how often consumed offsets are committed, and a longer interval reduces Kafka write amplification at the cost of more replay on rebalance.
curl -s http://connect:8083/connectors | jq .
curl -s http://connect:8083/connectors/postgres-source/status | jq .
curl -s http://connect:8083/connectors/postgres-source/tasks/0/status | jq .
curl -X POST http://connect:8083/connectors/postgres-source/pause
curl -X PUT http://connect:8083/connectors/postgres-source/config -d @updated-config.json
The REST control plane is also the operational interface. Pause a connector before investigating a downstream outage so it does not continue consuming and buffering. Restart a single failed task rather than the whole connector to minimize disruption. Monitor consumer lag on the Connect internal consumer group, which behaves like any other Kafka consumer group and can fall behind if the external system slows down. The most common production failure mode is not a crash but a slowdown: the connector stays running while lag grows silently, so alert on lag rather than only on task state.
Common Mistakes
Setting tasks.max higher than the number of source tables or topic partitions
Fix: Match task count to the natural parallelism of the workload and let the framework rebalance
Using JSON converter without schema support in production
Fix: Adopt Avro or Protobuf with a schema registry so evolution is checked at write time
Configuring a DLQ but never consuming it
Fix: Assign a DLQ processor and alarm on its lag so quarantined records get attention
Ignoring file size in S3 sink configurations
Fix: Set flush.size to the 128 to 256 MB range and add time-based rotation as a safety net
Best Practices
- Version connector configurations in source control and deploy through CI
- Prefer distributed mode in production so task rebalancing survives worker loss
- Pair every sink connector with a dead letter queue and a documented response
- Use timestamp plus incrementing mode for JDBC sources that support it
- Alarm on Connect consumer lag and task restart counts, not only on task state
Interview Questions
Q1: Explain the relationship between connectors, tasks and workers.
A connector is a configuration declaring what data moves, the runtime splits it into tasks which are the parallel units, and workers are the JVM processes that host those tasks and coordinate through Kafka-backed config, offset and status topics.
Q2: When would you use a dead letter queue instead of failing the task?
When the failure is confined to individual records rather than a systemic outage. The DLQ captures the poison message with error headers, the task continues, and a separate process repairs or alerts.
Q3: How do you prevent an S3 sink from creating tiny files?
Raise flush.size into the hundreds of megabytes and pair size-based rolling with rotate.interval.ms so low-traffic topics still produce on a predictable schedule.
Q4: What does an SMT do and when is it the wrong tool?
It reshapes each record in flight inside the worker. It is the wrong tool for logic requiring external calls, heavy computation, or schema changes that downstream consumers were not compiled against.
Key Takeaways
- Workers host tasks, connectors declare intent, and Kafka-backed topics give the cluster its resilience
- Choose converters for schema evolution support, not just current convenience
- JDBC sources need a clear new-row strategy; Debezium is the answer when deletes matter
- SMTs are for lightweight reshaping, not business logic or schema-breaking changes
- A dead letter queue without a consumer is just slower data loss