Data Engineering Bug Report Paid

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.

Ryan Pham Ryan Pham @ryan_bugs · December 02, 2026 · 7 min read · 15 Views
657-kafka-recordtoolargeexception-message-size-settings

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 checks max.request.size against 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?

max.request.size

Producer

1048576

Size of a single record (serialized, before compression) and of a produce request

Yes, client side

message.max.bytes

Broker

1048588

Largest record batch the broker accepts (after compression)

Yes

max.message.bytes

Topic

1048588

Same as above, per topic, overrides broker default

Yes

replica.fetch.max.bytes

Broker

1048576

Bytes per partition followers try to fetch

No, a larger batch is still fetched

max.partition.fetch.bytes

Consumer

1048576

Bytes per partition per fetch

No, a larger batch is still returned

fetch.max.bytes

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, compression.type=zstd, linger.ms=10

Go consumer

franz-go, default fetch settings

invoice-events

24 partitions, RF 3, default max.message.bytes

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

#kafka #recordtoolargeexception #producer #message-size #claim-check
Written by
Ryan Pham @ryan_bugs

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.

Advertisement

Comments

0

No comments yet. Be the first to comment!

Sign In to post a comment.