• 2 Minute Streaming
  • Posts
  • Queue Semantics and Share Consumer Groups in Apache Kafka (KIP-932)

Queue Semantics and Share Consumer Groups in Apache Kafka (KIP-932)

šŸš‡ no more over-partitioning when all you need is a queue.

Vanilla Consumers

Kafkaā€™s regular consumer groups are great for scalability and preserving message order.

But. They donā€™t address all use cases.

The ordering requirement forces a single consumer to have exclusive access to a set of partitions - a one-to-many mapping.

Scaling consumer groups up can become tricky - you canā€™t have more consumers than partitions - at mostĀ one-to-one.

So, people usually over-partition because of this.

Further, there is no real per-record state. Consumers pull many messages and only advance to an offset if all records before that have been processed.

How do you signal that a single message out of the large batch failed to be processed and should be retried by another consumer?

Message Queue

What if:

  • you donā€™t need ordering

  • you need per-record acknowledgement/retries

The current model doesnā€™t work well with traditional message queue semantics. Those usually support the use case of a job queue - many agents pulling from a pool of jobs in some order.

KIP-932 - Queues for Kafka

ā

KIP-932 proposes to extend Kafka to introduce the notion of share (consumer) groups.

Share groups allow a many-to-many mapping of partitions ā†’ consumers.
They are basically a different flavor of consumer groups.

One doesnā€™t even need to write much new code - a shared group can be run with the exact same API that Kafka consumers support today, just a different configuration (group.type=share).

Share groups treat the whole topic as a single queue.

All the consumers read from all of the partitions - there is no sticky mapping.

This allows you to have a job queue with the extra Kafka benefits of:

  • āœ… no max queue depth

  • āœ… the ability to replay records

  • āœ… Kafkaā€™s greater ecosystem

These queues have at least once semantics. There is also no order.

It elegantly allows you to use Kafka as if it were a queue without changing anything underlying:

  • The same old topic is there.

  • The same old vanilla consumer groups can still be there consuming from the same topic.

How it Works šŸ¤”

Brokers will have a new component that manages share groups - the Share Group Coordinator.

It will keep a sliding window of records per partition which will have every record inside that window be consumable by the share group. These are called the in-flight records.

The broker will track the state of processing for each record in that window, and serve them to share consumers. When consumers acknowledge their consumption, the window will progressively move forward.

Once fetched, the record will be marked as acquired by that particular consumer. A lock is kept on them for up to share.record.lock.duration\.ms so that if the consumer crashes, the message gets released.

Poison records are also handled - the delivery attempts of acquired-but-not-processed messages are counted, up to a maximum. After that, the record is marked as archived and not sent anymore.

Liked this?

Help support our growth so that we can continue delivering valuable content!

Meta

Note that KIP-932 is still in discussion! Everything is up for change. If you have opinions - go engage in the mailing list! Thanks to Andrew for the great proposal!

More Kafka? šŸ”„

this wonā€™t be the case for long!

chart showing how Kafka's log compaction works

ApacheĀ®, Apache KafkaĀ®, Kafka, and the Kafka logo are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.