What you are actually turning on
Without exactly-once support, a source task writes records to Kafka first and commits its source offsets later, on offset.flush.interval.ms. If a worker crashes between the two, the restarted task replays from the last committed offset and you get duplicates.
KIP-618 (Kafka 3.3) closes that gap. Each source task uses a transactional producer. The records and the source offsets go into the same Kafka transaction. Before tasks start after a rebalance or reconfiguration, the leader fences older producers from previous generations of the connector, so a zombie task cannot commit.
The guarantee only covers the Kafka side. You still need:
- A connector that can resume exactly from its stored offsets. Not every connector can. Check its documentation for exactly-once support.
- Downstream consumers that read with
isolation.level=read_committed. Aread_uncommittedconsumer still sees records from aborted transactions.
Work through the sections below in order. Each item is something that has broken a real rollout.
Broker prerequisites
- Brokers support transactions and the transaction state log is healthy. On small or dev clusters, check that
transaction.state.log.replication.factorandtransaction.state.log.min.israre not higher than the number of brokers. If they are, the first transactional producer hangs onInitProducerId. - You have checked the topic used for transaction state:
kafka-topics.sh --bootstrap-server $BOOTSTRAP --describe --topic __transaction_state | head -5
- No hanging transactions on the target topics before you start. Older failures can leave the last stable offset (LSO) pinned:
kafka-transactions.sh --bootstrap-server $BOOTSTRAP find-hanging --broker-id 1
kafka-transactions.sh --bootstrap-server $BOOTSTRAP list
Worker configuration and the two-phase rollout
exactly.once.source.support is a worker setting with three values: disabled (default), preparing and enabled. It only applies in distributed mode.
Warning
Do not flip a running cluster straight from
disabledtoenabled. While workers run mixed settings, a worker with the feature disabled can still start tasks with no fencing. Roll every worker topreparingfirst, then roll every worker toenabled.
- Phase 1: set
exactly.once.source.support=preparingon every worker and do a rolling restart. - Phase 2: set
exactly.once.source.support=enabledon every worker and do a second rolling restart. - To back out, run the same two phases in reverse (
preparing, thendisabled). - The worker's
group.idis stable and documented. It is part of every transactional ID, so changing it changes the ACLs you need.
# connect-distributed.properties
group.id=connect-prod
exactly.once.source.support=enabled
# Internal topics read with read_committed once EOS is on
config.storage.topic=connect-prod-configs
offset.storage.topic=connect-prod-offsets
status.storage.topic=connect-prod-status
- Do not override producer settings that conflict with transactions. With EOS enabled, Connect sets
enable.idempotenceandtransactional.idon task producers itself. Aproducer.override.*or worker-level producer setting that disables idempotence makes tasks fail.
Security: ACLs for transactional IDs and fencing
This is the most common reason tasks stay UNASSIGNED or fail right after enabling the feature.
- Task producers use transactional IDs of the form
<group.id>-<connector>-<task>. The Connect principal needsWriteandDescribeon those IDs. A prefixed ACL on the group ID covers them. - The leader also writes the config topic transactionally, using the ID
connect-cluster-<group.id>. Grant that too. - Fencing uses the Admin client to fence producers. It needs the same
Writeon the transactional IDs. - On older brokers, also grant
IdempotentWriteon the cluster resource.
# Task and fencing producers
kafka-acls.sh --bootstrap-server $BOOTSTRAP --command-config admin.properties \
--add --allow-principal User:connect --operation Write --operation Describe \
--transactional-id connect-prod- --resource-pattern-type prefixed
# Leader's config-topic producer
kafka-acls.sh --bootstrap-server $BOOTSTRAP --command-config admin.properties \
--add --allow-principal User:connect --operation Write --operation Describe \
--transactional-id connect-cluster-connect-prod
kafka-acls.sh --bootstrap-server $BOOTSTRAP --command-config admin.properties \
--list --transactional-id connect-prod- --resource-pattern-type prefixed
- If connectors use their own offsets topic (see below), the principal can create, read and write that topic.
Connector configuration
Three connector-level settings matter.
| Setting | Values | What to choose |
|---|---|---|
exactly.once.support | requested (default), required | Use required for connectors where duplicates are unacceptable. Creation fails if the connector does not declare support, which is better than silently running at-least-once. Use requested for connectors that work exactly-once but don't report it. |
transaction.boundary | poll (default), interval, connector | See the next section. |
offsets.storage.topic | topic name | Optional per-connector offsets topic. Useful when the connector writes to a different Kafka cluster than the worker's internal topics. |
curl -s -X PUT -H "Content-Type: application/json" \
$CONNECT/connectors/orders-cdc/config -d '{
"connector.class": "<your source connector class>",
"tasks.max": "1",
"exactly.once.support": "required",
"transaction.boundary": "interval",
"transaction.boundary.interval.ms": "5000"
}'
# Validate before you deploy: errors on exactly.once.support show up here
curl -s -X PUT -H "Content-Type: application/json" \
$CONNECT/connector-plugins/<ConnectorClass>/config/validate -d @config.json \
| jq '.configs[] | select(.value.errors | length > 0) | .value'
-
transaction.boundary=connectoris only valid if the connector can define its own boundaries. Otherwise validation fails.
Choosing a transaction boundary
The boundary decides how often a transaction commits. It is a trade-off between overhead and how long data stays invisible to read_committed consumers.
| Boundary | Behaviour | Good for | Watch out for |
|---|---|---|---|
poll | One transaction per batch returned by poll() | Low-latency sources with healthy batch sizes | Very small polls create many tiny transactions and lots of commit markers |
interval | Commit every transaction.boundary.interval.ms (falls back to offset.flush.interval.ms) | Chatty sources that poll small batches | Consumers wait up to the interval to see data |
connector | Connector decides, for example per source transaction | CDC connectors that map to source transactions | Only if the connector supports it |
Tip
A
read_committedconsumer cannot read past the LSO. A long interval or a stuck task holding an open transaction looks like consumer lag that does not move, even though the producer is writing. Check the producer side before you scale consumers.
Fencing, rebalances and task count changes
- Expect a short pause on reconfiguration. When a connector's config or task count changes, the leader must fence the previous generation's producers before new tasks start. If fencing fails (usually ACLs or an unreachable broker), the new tasks do not start.
- Watch worker logs for fencing errors and
ProducerFencedExceptionon tasks. A single fenced task after a rebalance is expected. Repeated fencing points to two clusters sharing agroup.id, or a duplicate worker. - Never run two Connect clusters with the same
group.idagainst the same Kafka cluster. They fence each other's tasks.
curl -s $CONNECT/connectors/orders-cdc/status | jq '.connector.state, [.tasks[] | {id, state, worker_id}]'
curl -s "$CONNECT/connectors?expand=status" | jq 'to_entries[] | {name: .key, state: .value.status.connector.state}'
Testing it before you trust it
- In a test cluster, kill a worker hard (
kill -9) in the middle of a load. Then compare source row counts with distinct keys in the target topic, read with aread_committedconsumer. - Repeat with a task-count change and with a broker restart.
- Confirm that consumers and sink connectors downstream set
isolation.level=read_committed. For sink connectors on the same worker, useconsumer.override.isolation.level=read_committedif your client override policy allows it.
kafka-console-consumer.sh --bootstrap-server $BOOTSTRAP --topic orders \
--from-beginning --isolation-level read_committed \
--property print.key=true --timeout-ms 30000 | cut -f1 | sort | uniq -d | head
Prevent it next time
- Keep the worker
group.id, the transactional ID ACL prefix and the rollout phases in your runbook, next to the Connect version. - Alert when a connector's tasks are not
RUNNING, and onread_committedconsumer lag that stays flat while the producer is writing. - Treat
exactly.once.support=requiredas the default for any connector that feeds financial or customer-facing data, so an unsupported connector fails at deploy time. - Before every Kafka or Connect upgrade, rerun the hard-kill test. Names, defaults and connector support change between releases, so check your version's documentation.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get