Share Groups (Queues)
Kafka 4's queue semantics: many consumers per partition, per-record acks
Consumer groups give every partition to exactly one consumer. That's great for ordered stream processing and awkward for work queues: if jobs are slow and you need 50 workers, you need 50 partitions, and one slow job blocks every job behind it in that partition. Share groups (KIP-932, available in Kafka 4) add queue-style consumption to Kafka.
How they differ
| Consumer group | Share group | |
|---|---|---|
| Consumers per partition | Exactly one | Many |
| Max useful consumers | Number of partitions | Unbounded |
| Ordering | Per partition | None guaranteed |
| Progress tracking | One committed offset per partition | Per-record state: acquired, acknowledged, released, rejected |
| Redelivery | Rewind to the committed offset | That one record, after a lock timeout or release |
| Best for | Stream processing, ordered events | Independent jobs |
A share group's consumers acquire records for a time-limited lock, then acknowledge each one as:
- ACCEPT: done.
- RELEASE: give it back for redelivery (to anyone).
- REJECT: unprocessable; don't deliver again.
Records not acknowledged before the lock expires
(group.share.record.lock.duration.ms, 30 s) are redelivered, up to
group.share.delivery.count.limit (5) attempts. That's the same model as RabbitMQ or SQS, built on
Kafka's durable log.
Try it
The features check shows share groups are enabled on this cluster
(share.version level 1). One partition, two share consumers:
docker exec -i kafka-1 sh -c '
cd /opt/kafka/bin; B="--bootstrap-server localhost:19092"
./kafka-topics.sh $B --create --topic tasks --partitions 1
seq 1 20 | ./kafka-console-producer.sh $B --topic tasks
./kafka-configs.sh $B --alter --entity-type groups --entity-name workers \
--add-config share.auto.offset.reset=earliest
timeout 15 ./kafka-console-share-consumer.sh $B --topic tasks --group workers > /tmp/w1 &
timeout 15 ./kafka-console-share-consumer.sh $B --topic tasks --group workers > /tmp/w2 &
sleep 8; seq 21 40 | ./kafka-console-producer.sh $B --topic tasks; wait
echo "w1: $(grep -E "^[0-9]+$" /tmp/w1 | tr "\n" " ")"
echo "w2: $(grep -E "^[0-9]+$" /tmp/w2 | tr "\n" " ")"'
w1: 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
w2: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20Two consumers, one partition, both receiving records. A classic consumer group would leave the second consumer idle. (Records arrive in batches, so with this tiny load each consumer got one batch; with a real workload deliveries interleave.)
Share groups default to share.auto.offset.reset=latest: a new group
starts at the end of the partition. The first attempt at this lab,
without the kafka-configs.sh line, received nothing at all, because
every record was produced before the consumers started. Set it to
earliest per group if existing records should be delivered.
When to use them
Share groups make Kafka a reasonable choice for job queues when you already run Kafka: email sending, image processing, webhook delivery, anything where jobs are independent and the worker count should scale with load rather than with partitions.
Prefer a consumer group when order matters (events for an account, a CDC stream) or when you're doing stateful stream processing. Prefer RabbitMQ (the next module) when you need routing, priorities, or per-message TTLs.
Client support is still arriving: the Java client has KafkaShareConsumer;
check your library before designing around them.
Lab
- Reproduce the experiment above.
- Produce 2,000 records and run three share consumers. Compare counts per consumer.
- Run
kafka-share-groups.sh --describewhile they're running and after. - Try the same with a regular
--groupandkafka-console-consumer.sh. How many of the three receive anything?