Skip to content

feat(binding-kafka): share group stream for Kafka share groups - #3109

Merged
jfallows merged 24 commits into
developfrom
feature/mqtt-shared-subscriptions-1-kafka-share
Nov 17, 2026
Merged

jfallows merged 24 commits into
developfrom
feature/mqtt-shared-subscriptions-1-kafka-share

Conversation

@jfallows

@jfallows jfallows commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds a SHARE stream kind to binding-kafka for consuming Kafka share groups (KIP-932): per-record acquisition, acknowledgement and redelivery, with no partition ownership or owner election. This layer is the specs, the share protocol, the client factory and the cache fan-out. It does not depend on any other binding.

Part of #1801

SHARE stream contract

  • Begin carries the group id, an optional member id, the topic and filters.
  • Data carries partition offset, timestamp, key, headers (on INIT and FIN) and deliveryCount (0 on the client hop means not reported).
  • An acquired flush after each partition's records carries lockTimeoutMillis and the acquired ranges with delivery counts.
  • An app-to-zilla flush carries ACCEPT, RELEASE or REJECT per record, with an optional correlation and error.

Client factory

  • One share-group member per stream, using FindCoordinator v6, ShareGroupHeartbeat, Metadata v13 (topic ids), ShareFetch and ShareAcknowledge v1, with ApiVersions negotiated per connection. An unsupported broker fails the stream and emits BINDING_KAFKA_API_VERSION_REJECTED.
  • The fetch response is decoded in a streaming fashion, without buffering the whole response.
  • Fetch sizing is configuration driven, like the standard client library: client.share.fetch.max.bytes, .max.records, .max.wait.millis, .min.bytes.
  • Acknowledgements piggyback on the next fetch and are sent on leave. The emitted lock timeout is conservative, measured from the request send.

Cache fan-out

  • The cache server holds one member per (binding, group id, topic) per worker and fans out in process; the cache client is a 1:1 pass-through.
  • Records are staged in an ephemeral cache partition log until the acquired flush, filters are evaluated on the complete record, and delivery goes to the next attached stream with window.
  • Unacknowledged records re-route in process when a stream detaches, and everything outstanding is RELEASEd when the last stream leaves. Expired records, and records with less than a configurable margin of lock left, are RELEASEd.

Kafka requirements

Kafka 4.1+ with the share.version=1 feature enabled. Share groups are a preview in 4.1.

Tests (test-first order is kept in the commit history)

  • specs/binding-kafka.spec: application and network share scripts, ShareIT (network and application) and ShareCacheIT.
  • runtime/binding-kafka: ClientShareIT, CacheShareIT, and unit tests KafkaShareRecordsTest, KafkaShareRangesTest, KafkaShareLockTest.

Stack

This is one layer of a stack of PRs for #1801. Each PR contains only the commits since the previous layer; merge in order.

# PR Layer Base
1 #3109 (this PR) binding-kafka: share group stream develop
2 #3110 binding-mqtt: shared subscriptions, server and client #3109
3 #3111 binding-mqtt-kafka: shared subscriptions for QoS 0 and 1 #3110
4 #3112 binding-mqtt: SUBACK after application streams begin #3111
5 #3113 binding-mqtt: complete in-flight deliveries when unsubscribing #3112
6 #3114 binding-mqtt-kafka: QoS 2 claim tickets (with engine test store assertions) #3113
7 #3115 binding-mqtt-kafka: epoch registry for the lifecycle of a shared subscription #3114
8 #3116 real-broker share stream fixes and mqtt.kafka.proxy example (top of the stack) #3115

Documentation: aklivity/aklivity-docs#181 (merge after the stack).

Test evidence

Run on this branch tip against origin/develop 57b7546 (checkstyle and license checks run in the validate phase of each build):

  • ./mvnw clean install -DskipTests -pl specs/binding-kafka.spec,runtime/binding-kafka -am -Dmaven.build.cache.enabled=false: OK
  • ./mvnw clean verify -pl specs/binding-kafka.spec,runtime/binding-kafka -Dmaven.build.cache.enabled=false: OK
    • specs/binding-kafka.spec: 255 unit tests and 589 spec ITs, 0 failures
    • runtime/binding-kafka: 257 unit tests and 495 ITs, 0 failures (ClientShareIT 40 and CacheShareIT 22 pass with none skipped)

Notes for reviewers

  • The whole stack is linearized by rebase and force push (the original work was a branch with a develop merge commit), so reviewers should expect SHA changes against any earlier view of these commits.
  • Commits keep the test-first order: the spec or test commit comes before the implementation commit.
  • Known limitations and follow-ups are tracked in Support MQTT 5 Shared Subscriptions via Kafka share groups #1801.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2

Describe a Kafka share group client stream (KIP-932): begin carries the
group id, member id, topic, filters and the maximum number of records
in flight; data carries the acquired record with its partition offset
and delivery count; flush carries a per-record acknowledgement of
ACCEPT, RELEASE or REJECT with an optional correlation.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Add paired client and server k3po scripts for the share stream at the
application level and at the wire level (FindCoordinator v6, Metadata
v13, ShareGroupHeartbeat v1, ShareFetch v1, ShareAcknowledge v1), with
spec-level ITs for both protocol sides and a client IT that drives the
scripts against the engine.

Scenarios cover receiving records, fragmented delivery, acknowledging
with ACCEPT, RELEASE and REJECT piggybacked on the next fetch or sent
as an explicit acknowledge, filtering of non-matching records,
multiple partitions, assignment changes, flow control bounded by the
stream window and the records in flight, leaving the group, and error
handling for coordinator, member, topic and authorization failures.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
… reset in specs

Every share group connection begins with an ApiVersions v0 exchange, ahead of
any SASL handshake and request, and the chosen version of each API used on the
connection (Metadata 13, FindCoordinator 6 on the bootstrap connection,
ShareGroupHeartbeat 1 on the coordinator, ShareFetch 1 and ShareAcknowledge 1 on
the partition leader) must fall within the advertised range. An absent API or an
excluded range rejects the stream with UNSUPPORTED_VERSION.

Adds scenarios for an absent share API, version range mismatch on the bootstrap,
coordinator and leader connections, application ABORT and RESET mid-stream, and
network abort of the coordinator and leader connections mid-session.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Adds flexible-version codec scopes for Metadata v13, FindCoordinator v6,
ShareGroupHeartbeat v1, ShareFetch v1 and ShareAcknowledge v1.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…r share group

KafkaRecordFilter evaluates ORed filters of ANDed key, header, headers and not
conditions over a decoded record, with the same semantics as the cache filter
conditions. KafkaShareRanges tracks disjoint ordered offset ranges.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Handles the SHARE stream kind with one share group member per stream:
per-connection ApiVersions negotiation, Metadata and FindCoordinator on a
bootstrap connection, ShareGroupHeartbeat on the coordinator connection, and
ShareFetch and ShareAcknowledge on each partition leader connection, with
acknowledgements piggybacked on fetch and a graceful leave on stream close.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
… error

A broker without the share feature enabled still advertises the share APIs but
answers ShareGroupHeartbeat with UNSUPPORTED_VERSION, which resets the stream.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
… from share data

The share stream delivers every record of a fetch response as it streams and
reports the acquired offset ranges with their delivery counts in a reply flush
once a partition's records are complete, so the per-record data extension no
longer carries a delivery count.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…sion rejected events

Share record data frames now precede the acquired ranges flush of their
partition; add scenarios for a record larger than the decode slot, a batch of
records, records outside the acquired ranges, acquired offset gaps and
compressed batches. Remove the client-level key filter scenarios, assert the
api version rejected event in the unsupported version scenarios.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…n specs

Report the whole batch of a flow controlled response in one acquired ranges
flush and match the api version rejected event messages formatted by the
binding.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
The event formatter resolved no title for the share group heartbeat, share
fetch and share acknowledge api keys and failed on events raised for them.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
… response

Decode the share fetch response progressively so a record or batch larger than
the decode slot streams to the application in fragments. Records are delivered
as they are decoded and the acquired offset ranges with their delivery counts
are reported in a reply flush once the acquired records of a partition are
decoded. Offsets acquired but not delivered are accepted or rejected, and the
client no longer evaluates record filters.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…tream credit

Share fetch requests carry the same static limits on every request, taken
from configuration like the regular fetch: the maximum bytes of a response
and the maximum records (also the batch size) of a response. The share begin
extension no longer carries a records limit, and the application window only
paces delivery of already requested records.

Add the client.share.fetch.max.bytes and client.share.fetch.max.records
properties. Scenarios that relied on a records limit to hold back the next
fetch until an acknowledgement was written now withhold the end of the
response until the acknowledgement is written, so the acknowledgement
piggybacks on the next fetch. Replace the window scenario with a response
larger than the application window delivered across window replenishments,
add leaving while a fetch is outstanding, and remove the scenarios that
exercised a records limit or a standalone acknowledge while the stream
could not fetch.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…tream credit

Send the configured maximum bytes, maximum records and batch size on every
share fetch, as the regular fetch does, instead of deriving them from the
application window and the unacknowledged record count. The next request is
sent once the previous response has been completely consumed; the application
window only paces delivery of requested records and network backpressure
holds the rest. Acquired but unacknowledged offsets are still tracked for
acknowledgement piggybacking and release on leave, but no longer gate fetches.

Acknowledgements always piggyback on the next share fetch, so the standalone
acknowledge request is now only sent when leaving, and the unused records
count helper is removed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…unt and optional member id

The share acquired flush reports the acquisition lock timeout of the fetch
response so a consumer of the stream knows how long the acquired records stay
locked. The share data extension reports the delivery count of a record, 0
meaning not reported, and the share begin extension makes the member id
optional for streams that do not own a share group member.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
… the kafka cache

The kafka cache server holds one share group member per share group and
fans out the acquired records to the share streams attached to the group,
distributing each record to exactly one stream, returning the records of a
stream that ends to the other streams and releasing the records when the last
stream ends. Records are held until their acquired range is known, filtered on
the complete record, dropped when their acquisition lock expires and withheld
from delivery when too little lock time remains.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…rios on stream readiness

Wait for the share stream to receive the record before the member stream
aborts, wait for the first acknowledgement before the second record is
distributed, and observe the reset of the initial direction before the abort
of the reply direction, as the cache group scenarios do.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
The kafka cache server holds one share group member per binding and share
group id and fans the acquired records out to the share streams attached to
the group. Records are staged in an ephemeral cache partition as they are
streamed, held until the acquired flush names their offset, evaluated against
the group filters on the complete record, and delivered to exactly one attached
stream with window, in rotation. Acknowledgements are forwarded to the member
stream and confirmations are routed back to the originating stream by
correlation. The records of a stream that ends are redelivered to the other
streams, and the records are released when the last stream ends.

Records are dropped when their acquisition lock expires and are released
instead of delivered when too little lock time remains. The member stream is
granted window only while the acquired records held stay under a bound. The
cache client keeps a share stream per attached stream as a pass-through.

Add the cache.server.share.staging.max.bytes, cache.server.share.staging.segment.bytes
and cache.server.share.lock.margin.percent properties. The record filter
evaluates the headers of a cache entry.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…timeout and uncorrelated rejected acknowledgement

The acquired flush reports the broker lock timeout minus the time elapsed
since the share fetch that produced the response was sent, floored at zero,
so a response held back in the network buffer does not overstate the
remaining lock. An engine clock that advances by a fixed step makes the
delayed response deterministic.

When the lock of a record held by the cache lapses before it is acknowledged,
the fan-out releases the record to the member stream instead of dropping it.
The expiry is driven by the signaler, held records are not delivered because
the attached stream has no window, and the release is awaited as an ordinary
frame. A lock that has already lapsed on arrival is released the same way.

A release the broker rejects as an invalid record state does not fail the
share stream and the offset no longer counts as in flight when leaving.

The staging bound scenario streams records larger than the member stream
credit, so the window withheld at the bound is exhausted and the stream only
completes when the bound resumes the window.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…an assignment change revokes the partition

An acknowledgement the application has requested a confirmation for and that
is still to be sent cannot reach the broker once the partition is revoked
from the member, so the confirmation reports an invalid record state instead
of success.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…ords and confirm revoked acknowledgements

The client factory reports the lock timeout of an acquired flush as the
broker lock timeout minus the time elapsed since the share fetch that
produced the response was sent, floored at zero, so a response held back in
the network buffer does not overstate the lock that remains.

The cache fan-out releases a record to the member stream when its lock
expires, whether or not it was delivered, instead of dropping it. The broker
rejects a release for a lapsed or reacquired record as an invalid record
state without affecting the member, and the client factory has already
cleared the offset from its in-flight set when the acknowledgement was
accepted, so the rejection of an uncorrelated acknowledgement is ignored.

A confirmation requested for an acknowledgement that is still to be sent when
an assignment change revokes the partition now reports an invalid record
state, as the acknowledgement can no longer reach the broker, instead of
reporting success when the next fetch completes.

The staging bound documentation states that the bound gates acknowledgement
and can be exceeded by one response, so it needs no relation to the share
fetch size.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
@jfallows
jfallows force-pushed the feature/mqtt-shared-subscriptions-1-kafka-share branch from 20210c7 to c50ab79 Compare November 17, 2026 01:45
@jfallows
jfallows merged commit bb2a4e0 into develop Nov 17, 2026
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants