Skip to content

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

Closed

Description

@jfallows

Describe the bug

The kafka produce client opens a new record batch for every record that has no producer id (producer id, epoch and sequence all -1). A produce request carries a single record batch per partition, and the client keeps one request in flight per partition stream, so each such record costs its own produce request and round trip. Records that arrive while a request is outstanding are never combined, however high the load.

The cause is the test that decides whether to start a new batch in KafkaClientProduceFactory: a new batch is opened when baseSequence >= sequence. A batch without a producer id is created with base sequence -1, and the incoming record's sequence is also -1, so the test is true for every record.

To Reproduce

Write two records back to back to the produce client with producerId=-1, producerEpoch=-1 and sequence=-1, with client.produce.max.request.millis set so both are queued before the first request is sent (200 is used by the other multi-record produce scenarios).

The new scenario message.values.no.producer.id (application and network scripts, with ClientProduceIT.shouldSendMessageValuesNoProducerId and peer-to-peer ProduceIT methods) does exactly this.

Expected behavior

The records are sent in one produce request as one record batch with recordCount 2 and lastOffsetDelta 1, with the batch header's producer id, epoch and base sequence left at -1.

Actual behavior

The first request carries a single record. Against the current client the scenario fails on request size: 125 bytes are sent where the batch of two records is 144 bytes, a difference of exactly one record. The second record goes out later in a request of its own.

A client without a producer id is limited to roughly one record per round trip per partition stream, so the Kafka round trip time bounds its produce rate.

Additional context

Records that do have a producer id are not affected: for them the sequence test is what starts a new batch when a sequence is not contiguous with the batch, and a change of producer id or epoch also starts a new batch. A Kafka record batch holds a single producer id, and a produce request carries exactly one batch per partition, so records from different producers cannot share a batch or a request.

Activity

  1. added
    bug
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions