Kafka RecordTooLargeException: the five message size settings that must agree
Raising one size limit moved RecordTooLargeException from the producer to the broker. Kafka has separate limits on the producer, broker, topic, replication and consumer side. How they interact, which ones are hard limits, and why the claim-check pattern was the real fix.
A new feature attached a rendered invoice snapshot (JSON with embedded line items, up to 3 MB for large B2B orders) to the invoice-events record. On the first day, about 0.4 percent of invoice events failed to publish:
org.apache.kafka.common.errors.RecordTooLargeException: The message is 2873144 bytes when serialized which is larger than 1048576, which is the value of the max.request.size configuration.
A developer raised max.request.size on the producer to 5 MB and redeployed. The error changed:
org.apache.kafka.common.errors.RecordTooLargeException: The request included a message larger than the max message size the server will accept.
After a platform engineer raised the topic limit, producing worked, but one consumer group, written in Go with an older client config, slowed to a crawl on the partitions holding big records.
Reproducing it
kafka-topics.sh --bootstrap-server broker1:9092 --create --topic big-repro --partitions 1 --replication-factor 3
head -c 2000000 /dev/urandom | base64 -w0 > big.txt
kafka-console-producer.sh --bootstrap-server broker1:9092 --topic big-repro < big.txt
The console producer fails with the max.request.size message. Adding --producer-property max.request.size=5000000 makes it fail on the broker instead.
What we ruled out
Compression would fix it. We had
compression.type=zstd. The producer checksmax.request.sizeagainst the serialized record size before compression, so compression did not help on the producer side.Only the producer needs changing. The second error proved the broker has its own limit.
The consumer slowdown was unrelated. It started at the same minute as the first large records arrived on those partitions.
Root cause
Kafka enforces message size in several independent places. We changed one, then two, but not all of them, and the payload simply did not belong in Kafka at that size.
What is happening under the hood
Setting | Where | Default | What it limits | Hard limit? |
|---|---|---|---|---|
| Producer | 1048576 | Size of a single record (serialized, before compression) and of a produce request | Yes, client side |
| Broker | 1048588 | Largest record batch the broker accepts (after compression) | Yes |
| Topic | 1048588 | Same as above, per topic, overrides broker default | Yes |
| Broker | 1048576 | Bytes per partition followers try to fetch | No, a larger batch is still fetched |
| Consumer | 1048576 | Bytes per partition per fetch | No, a larger batch is still returned |
| Consumer | 52428800 | Bytes per fetch response | No, same rule |
Since Kafka 0.10.1, fetch limits on the follower and consumer side are soft: if the first record batch in a partition is larger than the limit, it is still returned so progress is possible. That is why replication and consumption did not fail outright. But the consumer was fetching one huge batch per request, and our Go client's small buffer settings meant many round trips and allocations per message, which explained the crawl.
Note the units: producer max.request.size is per uncompressed record, while broker and topic limits apply to the compressed batch. A 3 MB JSON record that compresses to 600 KB passes the broker check but still fails the producer check unless max.request.size is raised.
Environment
Component | Version / value |
|---|---|
Apache Kafka | 3.9.0, KRaft, 6 brokers |
Java producer | kafka-clients 3.9.0, |
Go consumer | franz-go, default fetch settings |
| 24 partitions, RF 3, default |
Record size | p50 14 KB, p99.9 2.9 MB uncompressed |
Who is affected
Producers sending records over 1 MB uncompressed, which is common with embedded documents, images as base64, or batched "envelope" events.
Topics where only some of the limits were raised.
Consumers with small buffers or strict memory limits reading topics with occasional large batches.
This is a paid story
Subscribe to read the full content, access all paid stories, and support the authors.
Add a label
Embed this post
<iframe src="https://www.hibug.me/kafka-recordtoolargeexception-message-size-settings" width="700" height="420" frameborder="0" loading="lazy"></iframe>
I build and run the platforms other engineers ship on: CI/CD pipelines, Kubernetes clusters, GPU inference services, LLM features in production, and the cloud bills that come with all of it. I have also spent years writing and operating automated trading systems, where a rounding bug or a missed websocket message is not a log line but a position you did not intend to hold. Each post here starts from a real failure: the alert, the exact error, what we ruled out, the root cause, and how we proved the fix. Same path every time: Investigate, Explain, Fix, Verify. No hype, no price predictions, just engineering.
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.