Current state: Draft
Discussion thread:
JIRA:
Kafka Connect sink connectors consume from Kafka topics using traditional consumer groups.
In this model, each partition is exclusively assigned to one task. This creates two problems for Kafka-to-Kafka (and Kafka-to-external) pipelines:
1. Scaling is coupled to partition count.
If a topic has 12 partitions, you can run at most 12 sink tasks. I
ncreasing parallelism beyond the partition count requires repartitioning the source topic -- an operationally expensive and disruptive change.
2. Slow tasks block partitions.
If one sink task is slow (e.g., network latency to a downstream system), the records on its assigned partitions back up.
Other idle tasks cannot help because partition ownership is exclusive. This creates head-of-line blocking at the partition level.
3. Rebalance storms cause processing gaps.
When tasks are added, removed, or crash, consumer group rebalances revoke and reassign partitions.
During a rebalance, no task processes records from revoked partitions. With cooperative sticky rebalancing this is mitigated but not eliminated.
Share Groups (KIP-932) introduce queue semantics for Kafka consumers. Unlike consumer groups, Share Groups do not assign partitions exclusively.
Instead, records from a partition are acquired by any available consumer in the group. After processing, the consumer acknowledges the record (ACCEPT, RELEASE, ARCHIEVED, or REJECT).
This provides:
- Elastic scaling independent of partition count.
50 tasks can process a 12-partition topic because records are distributed at the record level, not the partition level.
- No head-of-line blocking.
If one task is slow, acquired records time out and are re-delivered to another task.
- No rebalance disruption.
Share Groups have no partition assignment protocol. Adding or removing tasks does not trigger reassignment of partitions.
Kafka Connect is the standard framework for building data pipelines into and out of Kafka. Integrating Share Groups into Connect's sink connector
runtime gives every existing sink connector access to queue semantics with a configuration change only -- no connector code modifications required.
| Mode | Guarantee | Mechanism |
|---|---|---|
| At-least-once(default) | Every record is delivered at least once; duplicates possible on failure | ShareConsumer.acknowledge(ACCEPT) after successful task.put(); records released on failure for re-delivery |
| Exactly-once | Every record is delivered exactly once | KIP-1289 transactional acknowledgments: producer.sendShareAcksToTransaction() binds acknowledgments to the output transaction |
At-least-once is the initial target. Exactly-once requires KIP-1289 (Transactional Acknowledgments for Share Groups) to be implemented and is described as a future phase.
This KIP integrates with KIP-1191. In Share Group mode, Connect uses `AcknowledgeType.REJECT` for fatal errors and relies on the broker-side DLQ configured by KIP-1191. Retriable failures use `AcknowledgeType.RELEASE`. If a DLQ is configured for the share group, the broker is the single source of DLQ records; Connect does not emit its own DLQ records in this mode.
For exactly-once, records with pending transactional acknowledgments must not be re-delivered while the transaction is open; KIP-1289 must suppress or renew acquisition locks until commit/abort. Operationally, `share.acquisition.lock.timeout.ms` must exceed worst-case `task.put()` plus transaction commit latency, otherwise duplicates are possible even with EOS.
- Add Share Group support to Kafka Connect sink connectors via a new `WorkerShareSinkTask`, with no changes required to the `SinkTask` API.
- Config-driven enablement (`consumer.override.group.protocol=share`) with per-connector overrides.
- At-least-once delivery for all sinks using Share Groups.
- Exactly-once delivery only for Kafka-to-Kafka pipelines within the same cluster, gated by KIP-1289 and a transactional producer.
- Share Group–specific metrics integrated into existing `sink-task-metrics` group.
- Share Group support for source connectors and MirrorMaker 2 (separate effort).
- Exactly-once delivery for cross-cluster Kafka-to-Kafka pipelines (source cluster A → sink cluster B).
- External two-phase commit coordinators or cross-cluster transactional protocols.
- Changes to the public `SinkTask` API or connector implementations.
| Property | Type | Default | Description |
consumer.group.protocol | string | consumer | Existing property. When set to share, the Connect worker creates a KafkaShareConsumer instead of a KafkaConsumer for sink tasks. |
| Property | Type | Default | Description |
consumer.override.group.protocol | string | (inherited from worker) | Per-connector override. Set to share to opt a single connector into queue semantics. |
share.group.id | string | connect-<connector-name> | The Share Group ID. Defaults to the same naming convention as consumer groups. |
share.acknowledgement.mode | string | explicit | explicit: worker calls acknowledge(ACCEPT) after task.put() succeeds. implicit: acknowledgments are sent on the next poll() (simpler, lower latency, weaker guarantee). |
share.acquisition.lock.timeout.ms | int | 30000 | Maximum time a record remains in ACQUIRED state before the broker releases it for re-delivery. Must be greater than the expected task.put() latency. |
share.delivery.semantics | string | at-least-once | at-least-once or exactly-once. Exactly-once requires KIP-1289 and a transactional producer. |
share.max.delivery.count | int | 5 | Maximum number of times a record can be re-delivered before being sent to the Dead Letter Queue (if configured). Maps to Share Group's group.share.record.lock.partition.limit. |
A new internal class in `org.apache.kafka.connect.runtime` that extends `WorkerTask` and drives the `SinkTask` using a `KafkaShareConsumer` instead of a `KafkaConsumer`. This is the core runtime change.
```
// New class: parallel to WorkerSinkTask but backed by ShareConsumer
class WorkerShareSinkTask extends WorkerTask<ConsumerRecord<byte[], byte[]>, SinkRecord> {
private final ShareConsumer<byte[], byte[]> shareConsumer;
private final SinkTask task;
// ...
}
```
Note: The existing `SinkTask` interface is not modified. Connectors do not need code changes. The `put(Collection<SinkRecord>)` contract remains the same.
The difference is entirely in the worker runtime:
| Aspect | WorkerSinkTask (today) | WorkerShareSinkTask (proposed) |
| Consumer | KafkaConsumer | KafkaShareConsumer |
| Subscription | consumer.subscribe(topics, rebalanceListener) | shareConsumer.subscribe(topics) |
| Poll | consumer.poll() | shareConsumer.poll() |
| Offset tracking | currentOffsets map + consumer.commitSync() | Per-record shareConsumer.acknowledge(record, ACCEPT) + shareConsumer.commitSync() |
| Rebalance | ConsumerRebalanceListener calling task.open()/close() | No rebalances. task.open() called once at startup for all subscribed topics. |
| Failure handling | RetriableException -> pause consumer, retry batch | RetriableException -> acknowledge(RELEASE) for batch, records re-delivered by broker |
The existing method that builds consumer properties is modified to detect `group.protocol=share` and construct `KafkaShareConsumer` configs instead of `KafkaConsumer` configs:
```
// In Worker.java
static Map<String, Object> baseConsumerConfigs(...) {
Map<String, Object> consumerProps = new HashMap<>();
String groupProtocol = // resolve from worker + connector config
if ("share".equals(groupProtocol)) {
consumerProps.put(ShareConsumerConfig.GROUP_ID_CONFIG,
connConfig.getString("share.group.id", SinkUtils.consumerGroupId(connName)));
// Share consumer specific configs
consumerProps.put(ShareConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, config.bootstrapServers());
} else {
// existing consumer group config path (unchanged)
consumerProps.put(ConsumerConfig.GROUP_ID_CONFIG, SinkUtils.consumerGroupId(connName));
consumerProps.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
// ...
}
return consumerProps;
}
```
These sensors are only registered by `WorkerShareSinkTask` -- they are not present when using a traditional `KafkaConsumer` via `WorkerSinkTask`.
This avoids publishing meaningless zeros and keeps dashboards clean. Operators can use the presence/absence of these metrics to confirm whether a connector is running in Share Group mode.
All metrics are registered under the existing `sink-task-metrics` group (same as `sinkTaskGroupName` in `ConnectMetricsRegistry`), tagged with `connector` and `task`.
This keeps them co-located with the existing `sink-record-read-total`, `sink-record-send-total`, etc. and avoids a separate metric namespace.
| Sensor Name | Metric Name | Type | Traditional Consumer (group.protocol=consumer) | Share Consumer (group.protocol=share) |
sink-record-acquire | sink-record-acquire-rate | Rate | not registered | Records/sec acquired from the share group |
sink-record-acquire-total | CumulativeSum | not registered | Total records acquired from the share group | |
sink-record-acknowledge | sink-record-acknowledge-rate | Rate | not registered | Records/sec acknowledged (ACCEPT) |
sink-record-acknowledge-total | CumulativeSum | not registered | Total records acknowledged (ACCEPT) | |
sink-record-release | sink-record-release-rate | Rate | not registered | Records/sec released (RELEASE) for re-delivery |
sink-record-release-total | CumulativeSum | not registered | Total records released for re-delivery | |
sink-record-reject | sink-record-reject-rate | Rate | not registered | Records/sec rejected (REJECT) to DLQ |
sink-record-reject-total | CumulativeSum | not registered | Total records rejected to DLQ | |
acknowledge-time | acknowledge-time-max | Max | not registered | Max time (ms) between poll() and acknowledge() |
acknowledge-time-avg | Avg | not registered | Avg time (ms) between poll() and acknowledge() | |
sink-record-redelivery | sink-record-redelivery-total | CumulativeSum | not registered | Total records with delivery count > 1 |
Conversely, the following existing `WorkerSinkTask` sensors have no Share Group equivalent and are not registered by `WorkerShareSinkTask`:
| Existing Sensor | Why not applicable to Share Groups |
partition-count | Share Groups don't assign partitions exclusively to tasks. All tasks consume from all subscribed partitions. |
offset-seq-number | Share Groups don't use consumer offsets. Acknowledgments replace offset commits. |
offset-commit-completion | No offset commits in Share Groups. Replaced by sink-record-acknowledge. |
offset-commit-completion-skip | No offset commits to skip. |
The existing sensors that are shared between both task types:
| Sensor | Behavior |
sink-record-read | Registered by both. Counts records polled (same semantics). |
sink-record-send | Registered by both. Counts records delivered to task.put(). |
sink-record-active-count | Registered by both. In Share Groups, this is the number of records currently ACQUIRED but not yet acknowledged. |
put-batch-time | Registered by both. Time spent in task.put(). |
- No impact by default. The default `group.protocol` remains `consumer` (standard consumer group). Existing connectors continue to work identically.
- Opt-in only. Share Groups are enabled per-connector or per-worker via configuration.
- No connector code changes required. The `SinkTask` interface is unchanged. Any existing sink connector works with Share Groups without modification.
1. Pre-requisite: Kafka broker version must support Share Groups (4.0+).
2. Enable at worker level: Set `consumer.group.protocol=share` in `connect-distributed.properties` to make all sink connectors use Share Groups.
3. Or enable per-connector: Set `consumer.override.group.protocol=share` in the connector config JSON.
4. Tune acquisition lock timeout: Set `share.acquisition.lock.timeout.ms` to a value greater than the expected `task.put()` latency. The default of 30 seconds is suitable for most workloads.
5. Monitor: Use the new `share-sink-task.*` metrics to observe acknowledgment patterns and re-delivery rates.
To revert, remove the `group.protocol=share` configuration. The connector will resume using standard consumer groups.
Note that Share Groups and consumer groups maintain separate offset tracking, so the consumer group will resume from its last committed offset
(which may be behind the Share Group's position).
No existing features are deprecated. This is purely additive.
1. `WorkerShareSinkTaskTest`: Tests the core poll-put-acknowledge loop using a `MockShareConsumer`.
- Verify ACCEPT after successful `task.put()`
- Verify RELEASE after `RetriableException`
- Verify REJECT after unrecoverable exception
- Verify `commitSync()` is called at configured intervals
2. `WorkerTest` (modified): Verify that `baseConsumerConfigs()` returns correct configs for `group.protocol=share`.
3. `SinkConnectorConfigTest` (modified): Validate the new configuration properties and their defaults.
1. Basic Share Group Sink: Deploy a sink connector with `group.protocol=share` and verify all records are delivered.
2. Elastic Scaling: Start with 2 tasks, scale to 6, verify no records are lost and throughput increases.
3. Task Failure and Re-delivery: Kill a task mid-processing, verify records are re-delivered to surviving tasks within `acquisition.lock.timeout.ms`.
4. No Duplicate Loss: Produce N records, consume with at-least-once Share Group sink, verify received count >= N.
5. Interoperability: Verify that standard consumer group connectors and Share Group connectors can coexist in the same Connect cluster.
1. Long-running throughput test: Measure throughput and latency of Share Group vs. consumer group sink connectors under sustained load.
2. Chaos test: Randomly kill tasks and brokers, verify zero data loss with at-least-once semantics.