Skip to content

fix(binding-kafka): batch records that have no producer id - #3300

Merged
jfallows merged 2 commits into
developfrom
fix/3289-kafka-client-produce-batching
Nov 17, 2026
Merged

jfallows merged 2 commits into
developfrom
fix/3289-kafka-client-produce-batching

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

The produce client opened a new record batch whenever the batch's base sequence was not below the incoming record's sequence (baseSequence >= sequence). A record without a producer id carries sequence -1, and the batch it starts has base sequence -1, so the test held for every such record and each one became its own batch. A produce request carries a single batch per partition and the client keeps one request in flight per partition stream, so each record cost its own request and round trip.

The sequence test now applies only to records that have a producer id. Records without one share a batch until the producer id or epoch changes.

Two commits, test first:

  1. test(binding-kafka): send records without a producer id in one batch adds the scenario message.values.no.producer.id (producer id, epoch and sequence all -1, two records). It fails against the previous client: the first request carries one record, 125 bytes where the batch of two records is 144.
  2. fix(binding-kafka): batch records that have no producer id is the one-line change in KafkaClientProduceFactory.

Changed scenario

messages.fragmented.crc relied on one batch per record. To keep it deterministic and independent of the batching policy, each of its eight records now has a distinct producer id (epoch 1, sequence 0), so each is still its own batch and request. The batch header producer fields and CRCs in the network scripts are updated to match. The CRC literals were computed from the batch bytes; the same calculation reproduces the previous literal for producer id -1. Four of them are above 2^31 and are written as their signed 32-bit values because k3po parses integer literals as signed ints.

This scenario no longer covers fragmented values with a CRC on the path without a producer id.

Tests

  • ./mvnw clean install from the repository root with checks enabled passes (219 modules, build cache restored).
  • ClientProduceIT.shouldSendMessageValuesNoProducerId fails before the fix and passes after.
  • Peer-to-peer ProduceIT methods in specs/binding-kafka.spec (network and application) pass for the new scenario.

Not addressed

  • Throughput against a real broker is not measured here.
  • The client still keeps one request in flight per partition stream.

Fixes #3299


Generated by Claude Code

Two records written without a producer id (producer id, epoch and
sequence all -1) arrive at the produce client back to back. The produce
request must carry them as one record batch of two records, with the
batch header's producer id, epoch and base sequence left at -1.

The scenario fails against the current client, which sends the first
record on its own, so the batch holds one record where two are expected.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoTq7qqb5tJqF7DRxHv
The produce client opened a new record batch whenever the batch's base
sequence was not below the incoming record's sequence. A record without
a producer id carries sequence -1 and the batch it starts has base
sequence -1, so the test held for every such record and each one became
its own batch. A produce request carries a single batch per partition,
so each record cost its own request and round trip.

Apply the sequence test only to records that have a producer id. Records
without one now share a batch until the producer id or epoch changes.

The fragmented message CRC scenario relied on one batch per record. Give
each of its records a distinct producer id so each still produces its
own batch and request, and update the batch header fields and CRCs to
match.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoTq7qqb5tJqF7DRxHv
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.

binding-kafka: produce client sends each record without a producer id in its own batch and request

2 participants