Quick revision
The short answer
The error comes from the producer itself: max.request.size defaults to 1 MB and is checked against the serialised record before compression, so raising max.message.bytes on the topic never gets a chance to matter. We raise max.request.size to match the topic limit, keep the broker or topic limit above the compressed batch size, and know that follower fetching and consumer fetch sizes are soft limits in current versions. Then we turn on compression, and for documents that are regularly large we store them outside Kafka and send a reference.
What to remember
In this answer, we followed a 3 MB record along its path and saw that the producer's max.request.size, 1 MB by default and checked before compression, was the limit that failed, so the topic change alone could not fix it. We matched the producer limit to the topic's max.message.bytes, saw that follower and consumer fetch limits are soft in current versions, turned on compression, and noted that regularly large payloads belong in object storage with a reference in Kafka.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The error comes from the producer itself: max.request.size defaults to 1 MB and is checked against the serialised record before compression, so raising max.message.bytes on the topic never gets a chance to matter. We raise max.request.size to match the topic limit, keep the broker or topic limit above the compressed batch size, and know that follower fetching and consumer fetch sizes are soft limits in current versions. Then we turn on compression, and for documents that are regularly large we store them outside Kafka and send a reference.
Why this question is asked
Large records fail in a confusing way because several settings, on different machines, all limit size, and the error message does not always say which one fired. Interviewers ask this because it shows whether we understand the path a record takes and can read an error message rather than change settings at random. In this answer, we will follow a 3 MB record from producer to consumer, see each limit it meets, fix the configuration for this case, and then talk about when large payloads should not be in Kafka at all.
1Reading the Error Message First
RecordTooLargeException can be raised by the producer before anything is sent, or returned by the broker. In this case the message says the record is about 3,000,000 bytes when serialised, which is larger than 1048576, the value of max.request.size. That names a producer setting, so the topic change could not help: the record never left the application.
This is the general lesson: the limits apply in order along the path, and the first one that fails stops the record.
- Producer: max.request.sizeDefault 1 MB; checked on the serialised, uncompressed record
- Producer: buffer.memoryDefault 32 MB; must hold the record while it waits
- Broker: message.max.bytes or topic max.message.bytesAbout 1 MB by default; checked on the compressed batch
- Followers: replica.fetch.max.bytesSoft limit; an oversized batch still replicates
- Consumer: max.partition.fetch.bytes, fetch.max.bytesSoft limits; an oversized batch is still returned
5 steps in order. Play them, or step through them one at a time.
2The Producer Limit
max.request.size limits the size of a single request the producer sends, and the producer also checks each record against it. The check uses the serialised size before compression, so a 3 MB JSON document fails even if it would compress to 400 KB. We raise it to the same value as the topic limit; there is no benefit in allowing the producer to build records the broker will refuse.
buffer.memory, 32 MB by default, is also worth a glance: it must comfortably hold several large records while they wait to be sent, or send() blocks.
3The Broker and Topic Limit
The broker setting message.max.bytes, about 1 MB by default, limits the largest record batch the broker accepts, and max.message.bytes is the per-topic override. Because the broker sees the batch as the producer sent it, this limit applies after compression. The team already set the topic to 5 MB, which is right; the producer simply needed to match it.
4Followers and Consumers
Older Kafka versions required replica.fetch.max.bytes on the brokers to be at least the largest message, or followers could not replicate it. In current versions this is not an absolute limit: if the first batch in a partition is larger, the follower still receives it, so only old setups need it raised.
Consumers work the same way. max.partition.fetch.bytes (1 MB by default) and fetch.max.bytes (50 MB by default) are soft limits: an oversized first batch is still returned so the consumer can make progress. But low values mean each fetch carries only one large record, which slows consumption, so for a topic of large documents we raise max.partition.fetch.bytes to a few MB as well.
5Compression and the Claim-Check Alternative
JSON is repetitive text and often compresses to a fifth or less of its size, so compression.type=zstd or lz4 on the producer reduces network, disk and broker load immediately. Remember, though, that the producer's own check happens before compression, which is why max.request.size still had to rise.
If documents of several MB are normal rather than rare, Kafka is the wrong place for them. Large records make batches uneven, slow followers, use consumer memory and fill the page cache. The claim-check pattern stores the document in object storage such as S3 and publishes a small event with its key, size and checksum. Kafka then carries kilobytes, and the large bytes go to a system designed for them.
6Follow-up questions
Why does the broker check the compressed size but the producer the uncompressed one?
The producer checks each record as it is added to a batch, before the batch is compressed, so it only knows the uncompressed size. The broker receives the finished, compressed batch, and that is what it stores and limits.
Could I just set every limit to 100 MB to stop this happening?
We could, but very large records hurt the cluster: they hold request threads, increase replication lag and memory use on consumers, and make latency unpredictable for every other topic on those brokers. It is better to set the limit to the real need and move large payloads out of Kafka.
What does a consumer see if a record is larger than max.partition.fetch.bytes?
In current clients it still receives the record, because the first batch is returned even when it exceeds the limit. Very old clients could get stuck, which is where the old advice to raise consumer limits comes from.
7Conclusion
In this answer, we followed a 3 MB record along its path and saw that the producer's max.request.size, 1 MB by default and checked before compression, was the limit that failed, so the topic change alone could not fix it. We matched the producer limit to the topic's max.message.bytes, saw that follower and consumer fetch limits are soft in current versions, turned on compression, and noted that regularly large payloads belong in object storage with a reference in Kafka.
Open with
The exception is coming from the producer, not the topic. max.request.size defaults to 1 MB and the producer checks every record against it after serialisation and before compression, so a 3 MB document fails before it is sent and the topic setting never matters.
Then, if they want more
So I set max.request.size to 5 MB to match the topic, and in Spring Boot that goes under spring.kafka.producer.properties. On the broker side, message.max.bytes, or max.message.bytes as a topic override, limits the batch after compression; the team already set that to 5 MB.
Followers used to need replica.fetch.max.bytes raised, but in current versions it is not an absolute limit, and consumer fetch sizes are soft limits too, so oversized batches still come through, although I would raise max.partition.fetch.bytes so consumption is not slowed. I would also enable zstd or lz4 compression, because JSON usually shrinks a lot.
And if documents of several megabytes are normal, I would stop putting them in Kafka: store them in object storage and publish a small event with the key and checksum, the claim-check pattern.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "List the limits a large record must pass from producer to consumer, and fix the...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-clients-in-depth/cf1c2db61e/