You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@kafka.apache.org by "Aditya Kousik (Jira)" <ji...@apache.org> on 2026/09/17 19:29:00 UTC

[jira] [Created] (KAFKA-21122) ByteBuffer serialize method to the producer Serializer

Aditya Kousik created KAFKA-21122:
-------------------------------------

             Summary: ByteBuffer serialize method to the producer Serializer
                 Key: KAFKA-21122
                 URL: https://issues.apache.org/jira/browse/KAFKA-21122
             Project: Kafka
          Issue Type: Improvement
          Components: clients, producer 
            Reporter: Aditya Kousik
            Assignee: Aditya Kousik


The consumer read path avoids a per-record copy for the record value. KIP-863 added a ByteBuffer method to Deserializer so that CompletedFetch#parseRecord can hand the deserializer the record value straight from the fetch buffer:

 
{code:java}
default T deserialize(String topic, Headers headers, ByteBuffer data) { ... } {code}
 

The default falls back to the {{byte[]}} method, so existing deserializers are unaffected, and {{ByteBufferDeserializer}} overrides it to skip the copy.

The producer has no matching method. {{Serializer}} only returns {{{}byte[]{}}}:
{code:java}
byte[] serialize(String topic, Headers headers, T data);{code}
So a producer whose record value is already in a ByteBuffer has to copy it into a byte[] for every record. This is the case for a caller that holds data off the Java heap or in a reused buffer, for example a Netty ByteBuf exposed through nioBuffer(), or a service that forwards a payload it does not read.

We should consider adding the missing method so the write side matches the read side that KIP-863 already added.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)