How do you configure Kafka to handle large messages?
Instruction: Discuss the configuration changes needed in Kafka to efficiently process and manage messages that exceed the default maximum message size.
Updated
Official answer
First consider storing a large object in durable object storage and publishing an authorized, versioned reference with its size and integrity metadata. The object must remain readable for the required replay period, and an upload/event failure needs reconciliation. Kafka is often better used for events than for very large blobs.
If large records are required, size and test the complete path:
- Producer:
max.request.sizelimits a produce request and effectively caps the uncompressed record batch. Include serialization, record headers and request/batch overhead; a 10 MiB value does not fit safely under a 10 MiB request limit. - Topic/broker: topic
max.message.bytes, or broker defaultmessage.max.bytes, limits the accepted record batch after compression when compression is used. Do not assume compressed and uncompressed sizes are identical. - Replication: review
replica.fetch.max.bytesandreplica.fetch.response.max.bytesagainst the supported maximum batches and memory budget. - Consumer: review
max.partition.fetch.bytesandfetch.max.bytes. These are not absolute memory caps: Kafka can return the first oversized batch in the first nonempty partition to allow progress. Replication fetch limits have a similar progress exception.max.poll.recordslimits returned record count, not fetched byte size.
Allow headroom for concurrent partitions, decompression and application copies. Align connectors, stream processors, mirrors and any downstream limits too. Test the largest permitted incompressible and compressible records, a rejected over-limit record, replay and replication recovery. Raising every limit indiscriminately can create memory pressure and long tail latency.
Producer limits, topic limits, broker fetch limits, consumer fetch limits