๐ŸŽ‰ 75% of content is free forever โ€” Unlock Premium from $10/mo โ†’
CW
NEWSLIVESearch All Content
๐Ÿ’ผ Servicesโ„น๏ธ Aboutโœ‰๏ธ ContactView Pricing Plansfrom $10

Kafka Connect: Workers, Tasks and Transform Chains

Apache KafkaKafka Connectโญ Premium

Kafka Connect: Workers, Tasks and Transform Chains

Senior level ยท The integration runtime, how work is split across tasks, and where errors are supposed to go.

Prerequisites

  • !Kafka topics, partitions and offsets
  • !How a consumer group commits progress

What You'll Learn

  • 1Separate the roles of worker, connector, task and transformation
  • 2Deploy a connector over the REST API and read its status output
  • 3Choose between standalone and distributed deployment modes
  • 4Route malformed records to a dead letter queue without stopping the pipeline

A runtime, not another client library

Kafka Connect is a framework for moving data between Kafka and everything else without writing a consumer. The unit of deployment is a connector, which is configuration rather than code: you describe the source or sink, the credentials, the topics, and the runtime does the rest. The heavy lifting happens in tasks, and a connector is essentially a factory that decides how many tasks exist and how the work is divided among them.

A worker is the process that runs those tasks, and workers form a cluster using the same group coordination as consumers. In distributed mode, connector configuration is stored in a compacted internal topic, so any worker can restart and reconstruct the full picture. In standalone mode everything lives in one process and configuration changes are loaded from disk, which is convenient on a laptop and unsuitable in production because a restart loses every in-flight offset.

The connector versus task distinction explains most scaling behaviour. A JDBC source on a twelve-table database usually runs twelve tasks, one per table, because that is the natural unit of parallelism. A sink connector typically spreads topic partitions across its tasks. When you need more throughput you raise the task count, and the framework redistributes partitions automatically.

Source connectors: the shape you will write most

{
  "name": "orders-cdc-source",
  "config": {
    "connector.class": "io.debezium.connector.postgresql.PostgresConnector",
    "database.hostname": "postgres.internal",
    "database.port": "5432",
    "database.user": "connect",
    "database.password": "${file:/opt/secrets/pg.password}",
    "database.dbname": "orders_db",
    "topic.prefix": "cdc",
    "plugin.name": "pgoutput",
    "slot.name": "connect_slot",
    "publication.name": "connect_pub",
    "table.include.list": "public.orders,public.customers",
    "key.converter": "io.confluent.connect.avro.AvroConverter",
    "value.converter": "io.confluent.connect.avro.AvroConverter",
    "value.converter.schema.registry.url": "http://schema-registry:8081",
    "snapshot.mode": "initial",
    "heartbeat.interval.ms": "10000"
  }
}

Two settings deserve attention beyond the connection details. snapshot.mode controls the initial backfill: initial takes a consistent snapshot of the included tables before switching to log streaming, while no_data skips the snapshot for a database that was already captured. And the heartbeat record keeps the replication slot advancing during quiet periods, which stops an idle slot from accumulating bloat on the source.

Deploying and inspecting over the REST API

# Create the connector
curl -s -X POST http://connect:8083/connectors \
  -H "Content-Type: application/json" \
  -d @orders-cdc-source.json | jq .

# Read connector and per-task state
curl -s http://connect:8083/connectors/orders-cdc-source/status | jq .

# Pause, reconfigure, resume: the safe way to change settings
curl -X PUT http://connect:8083/connectors/orders-cdc-source/pause
curl -X PUT http://connect:8083/connectors/orders-cdc-source/config \
  -H "Content-Type: application/json" -d @orders-cdc-source-v2.json
curl -X PUT http://connect:8083/connectors/orders-cdc-source/resume

# Inspect the full task topology after a scale-out
curl -s http://connect:8083/connectors/orders-cdc-source/tasks | jq '.[].id'

A status response tells you three things: the connector state, each task state, and the stack trace of the last failure. A connector that reports RUNNING with a FAILED task is the common case, and it means the framework is healthy while one shard of the work is not. Restarting the whole connector in that state restarts every task and throws away progress on the shards that were fine; restart the failed task id instead.

Sink connectors and write semantics

{
  "name": "search-index-sink",
  "config": {
    "connector.class": "io.confluent.connect.elasticsearch.ElasticsearchSinkConnector",
    "topics": "enriched-orders",
    "connection.url": "http://search:9200",
    "key.ignore": "false",
    "write.method": "upsert",
    "behavior.on.null.values": "delete",
    "batch.size": "500",
    "linger.ms": "10",
    "flush.timeout.ms": "10000",
    "errors.tolerance": "all",
    "errors.deadletterqueue.topic.name": "connect-dlq",
    "errors.deadletterqueue.context.headers.enable": "true"
  }
}

write.method decides whether the sink inserts or upserts, and it is the setting that determines whether a replay is harmless. Combined with a key that is stable across retries, an upsert sink is naturally idempotent, which is why Kafka records keyed by entity id make sink operations safe without any transaction. behavior.on.null.values controls tombstones: delete is right for a compacted log where a null means the entity is gone, and none is right when nulls are just artefacts of a transform.

โš ๏ธPause before you edit

Changing a connector configuration while it runs forces a full stop and restart of every task. Pause the connector first, update the config, then resume, so running tasks are not torn down mid-batch.

Single message transforms: useful, limited, chainable

SMTs reshape one record at a time as it moves through the pipeline. They are declared in configuration as a comma-separated chain and applied in order, which makes them attractive for routing, field extraction and masking without deploying code.

public class NormalizeEmail implements Transformation<SinkRecord> {
    private String fieldName;

    @Override
    public void configure(Map<String, ?> configs) {
        this.fieldName = (String) configs.get("field");
    }

    @Override
    public SinkRecord apply(SinkRecord record) {
        if (record.value() == null) return record;
        Struct value = (Struct) record.value();
        String raw = value.getString(fieldName);
        if (raw == null) return record;
        value.put(fieldName, raw.trim().toLowerCase());
        return record.newRecord(record.topic(), record.kafkaPartition(),
            record.keySchema(), record.key(), record.valueSchema(), value,
            record.timestamp());
    }

    @Override
    public void close() { }
}

The limit worth stating in an interview is that an SMT sees exactly one record. It cannot deduplicate against a neighbour, join to a reference table, or batch. Anything requiring cross-record knowledge belongs in a Streams application or a KTable-backed consumer, not in a transform chain.

Dead letter queues and error tolerance

errors.tolerance has three values and they behave very differently. the default value is none, which fails the task on the first bad record. all tolerates every error and simply drops records unless you also configure a dead letter queue. explicit allows a specific list of exception classes and nothing else.

Routing to a DLQ needs both the tolerance and the destination: errors.tolerance set to all, errors.deadletterqueue.topic.name set, and errors.deadletterqueue.context.headers.enable turned on so the original topic, partition, offset and exception arrive as record headers. Without headers you get a payload you cannot attribute, and replaying it later becomes guesswork.

What exactly-once means for Connect

Source connectors achieve effectively exactly-once through idempotence: each record carries a stable key and the source records its position in its own transaction or log, so a retry re-emits the same key and a keyed consumer deduplicates. Sink connectors achieve it when the destination supports atomic batch writes, which is why the put method can wrap its work in a database transaction and commit offsets only after the batch lands.

Neither path protects you from a transform that calls an external API. The framework commits Kafka side effects atomically with offsets, and anything outside that boundary must carry its own idempotency key.

Deploying connectors without creating a single point of failure

A distributed Connect cluster is only as resilient as its worker layout. Running all tasks of a single connector on one worker means a worker restart takes down the entire pipeline, even though the cluster itself is healthy. The default task assignment spreads tasks across available workers, but it does not guarantee that a single connector's tasks are distributed: a connector with one task, or a connector whose tasks are pinned to a single worker by a rebalance that has not yet run, can leave an entire source or sink on a single process.

The operational fix is to give each connector a task count that matches the natural parallelism of the source, then verify after deployment that the tasks are actually spread. The Connect REST API reports task-to-worker assignment, and a quick check after every rollout catches the case where a new connector's tasks all landed on one worker because the rebalance had not completed when the check ran. Do not rely on the default rebalance interval for correctness; treat task distribution as a post-deploy verification step.

The second failure mode is configuration drift between environments. Because connector configuration lives in a compacted topic in distributed mode, it is not version-controlled by default. Teams that edit connector configuration through the REST API in production and maintain a separate YAML in the repository inevitably diverge, and the first time someone needs to roll back a change, they discover the live configuration is three edits ahead of the last reviewed version. Treat connector configuration as code: manage it through a deployment pipeline that writes to the REST API, store the desired state in a version-controlled file, and diff the live configuration against the desired state as part of a health check.

The third failure mode is a worker that accepts tasks but cannot actually run them, usually because its converters or transforms are missing from the classpath. The task will appear to start and then fail immediately, and the connector will show a failed state with an error that points at a class not found rather than at the missing dependency. Package the connector, its converters and its transforms into a single artifact deployed to every worker in the cluster, and verify with a smoke test after any worker upgrade that the artifact is present on every node.

Common Mistakes

Scaling a connector by adding workers when tasks are already maxed out

Fix: Check tasks.max first. Workers give you failure domains and process isolation; tasks give you parallelism, and you almost always need the second.

Letting a poison record fail the whole connector

Fix: Set errors.tolerance to all and configure a dead letter queue with context headers so one malformed record cannot halt an entire pipeline.

Editing connector configuration while it is running

Fix: Pause, update, resume. An in-place update restarts every task and discards progress on healthy shards.

Reaching for an SMT to do cross-record work

Fix: Transforms are per record by design. Move deduplication or enrichment into a Streams application with a state store.

Best Practices

  • Deploy connectors in distributed mode so configuration survives worker restarts and offsets live in Kafka
  • Give each connector a task count that matches the natural parallelism of the source, then tune upward only where metrics justify it
  • Always enable dead letter queue headers; they are the only way to attribute a failed payload later
  • Prefer stable record keys so sink upserts are idempotent and replays are harmless
  • Alert on task state rather than connector state, since one failed task is invisible in the aggregate

Interview Questions

Q1: What is the difference between a connector and a task?

A connector is the configuration and lifecycle object that figures out how the work divides. A task is the unit of parallelism that does the actual copying, and several tasks run concurrently across workers for one connector.

Q2: How does Connect avoid duplicates when a source task restarts?

The source records its position in the external system transactionally or in its own log and stores the Kafka offset for the task. On restart it resumes from the stored offset, and records are keyed so downstream consumers can deduplicate anything re-emitted.

Q3: What does errors.tolerance=all do on its own?

It swallows every exception and drops the record, with no trace unless you also configure a dead letter queue. Alone it converts a loud failure into silent data loss, which is why the two settings must be applied together.

Q4: When would you choose standalone over distributed mode?

Only for local development or a single low-volume integration on one machine. Distributed mode stores configuration in a compacted topic, balances tasks across workers, and survives worker restarts without manual intervention.

Q5: How would you evolve a schema flowing through a Connect pipeline?

Register schemas with a schema registry and set a compatibility level on the subject so incompatible changes are rejected at write time. Converters carry the schema id in the record, and consumers resolve it lazily, so rolling deploys stay safe.

Key Takeaways

  • Connectors are configuration, tasks are parallelism, and workers are the processes that host tasks in a cluster
  • Distributed mode stores configuration and offsets in Kafka, which is what makes restarts safe
  • Task count, not worker count, controls throughput, and one failed task shows only in the per-task status
  • SMTs reshape a single record; anything needing cross-record context belongs in a Streams application
  • Error tolerance without a dead letter queue converts failures into silent drops, so configure both or neither
๐Ÿ”’

Premium Content

Kafka Connect: Workers, Tasks and Transform Chains

You've previewed the first section. Unlock this full lesson and 900+ advanced tutorials with a Premium plan.

๐ŸŽฏEnd-to-end Projects
๐Ÿ’ผInterview Prep
๐Ÿ“œCertificates
๐ŸคCommunity Access

Already a member? Log in

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-13

โ€”
โ˜†โ˜†โ˜†โ˜†โ˜†
0 ratings

Rate & Feedback

Advertisement