RecordTooLargeException: The message is 1048577 bytes when serialized which is larger than 1048576, which is the value of the max.request.size configuration.
Checked against Kafka 4.2 · Oct 2026Community draft, not yet reviewed by a Kafka specialist
What it means
A record is larger than a size limit. The producer checks the serialized size before sending, against max.request.size (1048576 by default) and against buffer.memory, and says which one it hit at the end of the message. The broker has its own cap on the record batch size after compression: message.max.bytes (1048588 by default), which a topic can override with max.message.bytes. A refusal from the server arrives as MESSAGE_TOO_LARGE: "The request included a message larger than the max message size the server will accept."
Quick answer
Read the end of the message. "max.request.size" means the producer's own limit refused the record, and "buffer.memory" means it is bigger than the producer's whole buffer. If the server refused it, the broker or topic limit is the one to look at.
Likely causes, most common first
The payload really is that large
How to confirm
Log the serialized size before sending, or look at the largest records you produce.
Fix
Options are to compress the records (compression.type), split the payload into smaller ordered records that share a key, or store the payload elsewhere and send a reference to it. Raising limits is the alternative, covered next.
The producer limit max.request.size is too low
How to confirm
The message ends with "the value of the max.request.size configuration". The documentation describes max.request.size as limiting the size of a request and as effectively a cap on the maximum uncompressed record batch size.
confirm # producer configuration (default is 1048576) max.request.size=5242880Fix
Raise max.request.size on the producer, and make sure the broker and topic limits are at least as large (next cause), or the server will refuse the batch instead.
The broker or topic limit is too low
How to confirm
The server refused the record (MESSAGE_TOO_LARGE). The broker compares the batch size after compression with the topic's max.message.bytes, which takes its default from message.max.bytes.
confirm kafka-configs.sh --bootstrap-server localhost:9092 --describe --entity-type topics --entity-name ordersFix
Raise max.message.bytes on the topic, or message.max.bytes on the broker. The fetch limits replica.fetch.max.bytes, fetch.max.bytes and max.partition.fetch.bytes are documented as not absolute maximums: if the first record batch is larger than the limit, it is still returned so that progress can be made. They still decide how much memory a fetch can use, so keep them in line.
fix kafka-configs.sh --bootstrap-server localhost:9092 --alter --entity-type topics --entity-name orders --add-config max.message.bytes=5242880
Sources
Every claim above comes from these Apache pages, as of Kafka 4.2. If a page does not say it, this entry does not.
- KafkaProducer.java (4.2 source) (opens in a new tab)
- Producer configs (4.2 documentation) (opens in a new tab)
- Broker configs (4.2 documentation) (opens in a new tab)
- Topic configs (4.2 documentation) (opens in a new tab)
- Consumer configs (4.2 documentation) (opens in a new tab)
- Protocol error codes (4.2 documentation) (opens in a new tab)
- Basic Kafka operations (4.2 documentation) (opens in a new tab)
- ConfigCommand.scala (4.2 source) (opens in a new tab)
Was this helpful?
Report an issue (opens GitHub in a new tab)