[feature] Consumer group functionality
There doesn't appear to be an ability for multiple applications to consume from the same queue without the potential that an application could get redelivered a message/event that was already processed.
That way, multiple event/queueing technologies wouldn't be needed. If this is out of scope of this projec tthough, feel free to close/ignore
@aaronS7 Yeah, consumer groups are currently not supported in PicoMQ, but I don't see a hard reason not to support them, other than the need for server-side state management. So, it's good to have this issue open.
Hi @aaronS7,
PicoMQ now supports Kafka Protocol: https://picomq.com/docs/kafka, but with a few opinionated differences in usage.
Such as, topics can only ever contain 1 partition and recommended to create granular topics like Pico streams.
And naturally, consumer groups are supported! And a small read on the why https://picomq.com/docs/faq/why-not-kafka
I will try to test it out this weekend @addu390!
They do work! Although the end goal of using consumer groups for parallel work would be cool, know this is early in the projects journey. Excited to see where it goes!
@aaronS7 A new release went out yesterday, in an effort to unify the metadata storage model of streams, decoupled from the protocol. Meaning you can now produce and consume the same stream from any protocol. For example, create and produce with the Pico protocol and consume via the Kafka protocol, and vice versa.
Because of this, supporting consumers groups in Pico protocol should be very straight forward, and will be available soon.
And PicoMQ discord channel is now up.
Hi from discord!
When implementing this, I imagine we should add another query parameter to READ like group_id? And if there's no group_id, should we fall back to the current implementation (backed by S3StreamService::read or entirely switch to the batched one read_batched? There's a difference in locking and encoding between the two fns but I need to read more about it. If you have thoughts off the top of your head - lmk
@ankitpatel96 Yes, query param makes sense, but I would name it group (matches the existing short names: seq, count, bytes, live, etc.), with a Pico-Group header equivalent. Still group_id for Kafka.
On read vs read_batches, group param shouldn't affect this, just depends on the from. Also, internally they both use the same path.
More as a heads-up, the group store currently lives in pico-kafka/src/group/, you'd need to move that to pico-server, so both FEs can use it.
Lastly, for semantics:
- seq absent + group present: start from the group's committed offset or beginning if none.
- seq present + group present: seq wins. That's an explicit seek.
- Committed offset means
next record to read, same convention as Kafka, so an HTTP consumer and a kcat -G consumer in one group agree. - And initially, we can not have auto-commit on reads, with commit as a separate call.
Read and read_batches do seem to have some differences - read takes the gate.op lock is probably the biggest difference - not really sure why this difference exists though? Would appreciate some help untangling that.
Lastly, for semantics: seq absent + group present: start from the group's committed offset or beginning if none. seq present + group present: seq wins. That's an explicit seek.
just to double check - that would cause every other consumer in the group to fast forward to this offset, right? I'm not sure what kafka does here but I wonder if it throws an error. Should this only be allowed for an empty consumer group - like the consumer that sent this message would be the first consumer in that group?
Committed offset means next record to read, same convention as Kafka, so an HTTP consumer and a kcat -G consumer in one group agree. And initially, we can not have auto-commit on reads, with commit as a separate call.
AFAICT this is how it works in kafka since commit is a heavier operation than just reading. the clients seem to have automatic commits built in, but its not at the protocol layer.
read takes gate.op because it writes (get_entry), for the TTL deadline, so, may put_kv the registry entry. read_batches has none of that, so touch=false. Kafka Fetch retries on its own, so it skips the lock on purpose. I'd leave read as-is for this feature. I meant, both end with batches_from and the storage path is same.
Only an explicit commit moves the group's offset. Kafka is identical (client-local). So there's no "empty group only" rule on read. Put the guard on commit instead: a commit needs a valid lease for that stream.
Yeah, agreed. In Kafka it's a client-side timer issuing normal OffsetCommit, not in the protocol itself. We can do the same, i.e. server has read and commit as separate calls, clients can add a timer.