In a Kafka share group, how do acquisition locks and the AcknowledgeType values ACCEPT, RELEASE, REJECT and RENEW decide a record's fate?
answer
- record states on the broker
- lock timer, 30 seconds
- retry versus never again
- renew needs explicit mode
basics
~20 sFetching acquires each record for one share consumer under a lock (30 s by default); ACCEPT finishes it, RELEASE returns it for another attempt, REJECT archives it, RENEW extends the lock, and an expired lock returns it automatically.
solid answer
~40 sWhen a `KafkaShareConsumer` polls, the broker moves each delivered record from available to acquired for that member and starts an acquisition lock, 30 s by default (`share.record.lock.duration.ms` per group). The member then acknowledges it: `ACCEPT` marks it processed, `RELEASE` makes it available for another delivery attempt, `REJECT` archives it as unprocessable, and `RENEW` extends the lock while work continues (explicit mode only). If the member does nothing, the lock expires and the record becomes available again. Every acquisition counts as an attempt, and a record that has reached the delivery count limit (5 by default) is archived instead of being released, so retries are bounded.
go deeper
Remember the four types by intent: done, retry, give up, more time; and that an unacknowledged record comes back when its lock runs out.
Walk through the record states, the 30 s default lock, where it is configured, and why each acquisition counts toward the delivery limit.
Explain what happens when a lock expires mid-processing, how that causes duplicate work, and how lock duration, RENEW and idempotent handlers address it.
Treat lock duration and delivery limit as group policy: who owns those settings per share group, and what a mis-sized lock costs the whole group.
## Where the lock comes from A **share group** is a Kafka group whose members, the share consumers, read the same partitions together. To stop two members working on one record, the broker tracks a state for every in-flight record of each share-partition. The broker's `RecordState` enum includes `AVAILABLE`, `ACQUIRED`, `ACKNOWLEDGED` and `ARCHIVED`. When `KafkaShareConsumer.poll()` fetches, the broker moves each delivered record from `AVAILABLE` to `ACQUIRED` for that member and starts a timer: the **acquisition lock**. While it is held, no other member of the same share group is given the record. The lock lasts 30 seconds by default (broker config `group.share.record.lock.duration.ms`). A single share group can override it with the group config `share.record.lock.duration.ms`, which the broker bounds between `group.share.min.record.lock.duration.ms` (15 s) and `group.share.max.record.lock.duration.ms` (60 s). The client can read the value in force with `acquisitionLockTimeoutMs()`. Every acquisition is one **delivery attempt**, and the broker counts them per record. ## The four acknowledgement types The member settles a record by acknowledging it with an `AcknowledgeType`: | Type | Meaning | Record afterwards | |---|---|---| | `ACCEPT` | processed successfully | acknowledged, never delivered again | | `RELEASE` | not processed, may be retried | available for another delivery attempt | | `REJECT` | unprocessable | archived, never delivered again | | `RENEW` | still being processed | stays acquired by this member, lock extended | - Use **`ACCEPT`** once the work is done. - Use **`RELEASE`** for a transient failure — a downstream timeout — so the record goes back and any member may take it next. - Use **`REJECT`** for a permanent failure, such as a payload that can never be parsed. It stops further delivery attempts at once. - Use **`RENEW`** when processing will outlast the lock. It needs explicit acknowledgement mode, and the renewed record is returned again by the next `poll()`, so the application must still settle it with a final type later. A group can switch renewal off with the group config `share.renew.acknowledge.enable` (default `true`, added in 4.3). ## When nobody acknowledges If the member crashes, stalls or simply never acknowledges, the lock expires and the record goes back to `AVAILABLE` for another attempt. This is what keeps a share group making progress when consumers fail: no record stays stuck behind a dead member. The delivery count is the backstop. When a record that has already been delivered the maximum number of times would become available again — after a `RELEASE` or an expired lock — the broker archives it instead. The limit is the broker config `group.share.delivery.count.limit` (default 5); from 4.3 a single group can override it with `share.delivery.count.limit`, bounded by `group.share.min.delivery.count.limit` (2) and `group.share.max.delivery.count.limit` (10). ## Limits on what can be locked The broker also caps how many records of one share-partition may be acquired at once: `group.share.partition.max.record.locks`, default 2000. When the cap is reached, fetches return no further records from that partition until locks are settled or time out. A slow group therefore throttles itself instead of locking the whole log. ## How the lock interacts with fetching - In the default `share.acquire.mode=batch_optimized`, a fetch acquires records along stored batch boundaries, possibly more than `max.poll.records`, and the client may prefetch the next batch. Prefetched records are already acquired, so their locks are running while they wait in the client's buffer. - With `share.acquire.mode=record_limit`, the consumer fetches no more than `max.poll.records` at a time and does not prefetch, which gives tighter control over when locks begin — the better choice when each record takes seconds. - Liveness is separate from locks: a share consumer must keep calling `poll()` within `max.poll.interval.ms` or it proactively leaves the share group. - `RENEW` travels like any other acknowledgement, on the share-fetch request of the next `poll()` or on a commit, so a consumer whose loop has stalled cannot renew either. ## Failure cases worth knowing 1. **Lock expires mid-processing.** The record is delivered to someone else while the first member is still working on it. The first member's later acknowledgement fails (the record's state is no longer valid for it), and the work runs twice. Size the lock above normal processing time, or renew. 2. **Releasing in a hot loop.** Each `RELEASE` leads to another acquisition, and each acquisition spends a delivery attempt; a record that fails for a permanent reason and is always released is archived only after the full limit, having occupied a lock each time. 3. **Ignoring the outcome.** When acknowledgements ride on the next `poll()`, a failed commit raises no exception; call `commitSync()` or register an acknowledgement commit callback to see it.
- In a Kafka share group, what limits how many records can be locked at the same time?The broker config `group.share.partition.max.record.locks` (default 2000) caps acquired records per share-partition, and from 4.3 a group can set `share.partition.max.record.locks` within broker bounds. At the cap, fetches return nothing more from that partition until acknowledgements or expired locks free records, so a slow group throttles itself.
- How does a Kafka share consumer keep a record whose processing takes longer than the lock?In explicit acknowledgement mode it acknowledges the record with `AcknowledgeType.RENEW` on each pass of its poll loop while the work runs, typically on another thread. A renewed record is returned again by `poll()` and must eventually get `ACCEPT`, `RELEASE` or `REJECT`. A lost connection to the partition leader or a leadership change ends the attempt anyway.
Work tickets on a board: taking one gives you 30 seconds of exclusive hold. You mark it done, pin it back for someone else, bin it as hopeless, or ask for more time; walk away and it goes back on the board, and a ticket taken five times without being finished is binned for good.
- REJECT puts the record back so another member can retry it.
- An expired acquisition lock counts as a successful acknowledgement.
- A released record is appended to the topic again as a new copy.
- RENEW works in the default implicit acknowledgement mode.
- The lock duration is a client config set on each share consumer.
Checked against Apache Kafka 4.3.1; the per-group share.delivery.count.limit and share.renew.acknowledge.enable configs were added in 4.3.