Learn Labs
Consumers

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.

tasks P0consumer groupworker 1gets everythingworker 2idletasks P0share groupworker 1records 21-40worker 2records 1-20one partition: a consumer group can use one worker; a share group (KIP-932) spreads records across many, acked one by one

How they differ

Consumer groupShare group
Consumers per partitionExactly oneMany
Max useful consumersNumber of partitionsUnbounded
OrderingPer partitionNone guaranteed
Progress trackingOne committed offset per partitionPer-record state: acquired, acknowledged, released, rejected
RedeliveryRewind to the committed offsetThat one record, after a lock timeout or release
Best forStream processing, ordered eventsIndependent 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 20

Two 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.)

kafka-share-groups.sh $B --listkafka-share-groups.sh $B --describe --group workersstart offset and lag per partitionkafka-share-groups.sh $B --describe --group workers --memberskafka-share-groups.sh $B --delete --group workers

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

  1. Reproduce the experiment above.
  2. Produce 2,000 records and run three share consumers. Compare counts per consumer.
  3. Run kafka-share-groups.sh --describe while they're running and after.
  4. Try the same with a regular --group and kafka-console-consumer.sh. How many of the three receive anything?

On this page