Kafka Producer RecordTooLargeException
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
RecordTooLargeException means the producer tried to send a record or request that exceeded one of Kafka's size limits. The fix is rarely "raise one setting and move on" because large-message problems usually involve producer limits, broker or topic limits, consumer fetch limits, and the broader question of whether the event should be that large in the first place.
Where Kafka Enforces Size Limits
A message can fail at several points along the path:
- the producer may reject the request because it exceeds
max.request.size - the broker or topic may reject the record because of message-size limits
- the consumer may later fail to fetch the message if its fetch limits are too low
That means large-message handling is a pipeline problem, not only a producer problem.
Reproducing the Error
Here is a simple Java example that can trigger the exception if the payload exceeds the current limits:
The actual failing limit depends on the cluster configuration.
Producer-Side Settings
The first setting to inspect is often:
This controls the maximum size of a request the producer will send. If the serialized record exceeds this value, the producer fails before the broker even gets involved.
But increasing only this setting is not enough if:
- the broker still rejects the record
- the topic limit is lower
- consumers cannot fetch the message later
Broker and Topic Limits
Kafka brokers also enforce message-size constraints. Depending on how the cluster is configured, a large record may need a higher broker-wide or topic-specific maximum message size.
The exact property names vary by where you apply them, but the important idea is simple: the producer and the broker must agree on what size is acceptable. Raising the producer ceiling alone only moves the failure downstream.
Consumer Fetch Limits Matter Too
A surprisingly common mistake is fixing publishing while forgetting the read side. Consumers may need larger fetch settings if they are expected to read the same large records successfully.
Typical consumer-side limits to consider include:
- '
max.partition.fetch.bytes' - '
fetch.max.bytes'
If those stay too small, consumers can lag or fail even after the producer-side exception is gone.
Compression Can Help
If the payload is text-heavy or repetitive, compression may reduce the effective request size:
Compression is useful, but it is not a design substitute. If your event is fundamentally huge, compression may only postpone the problem.
Better Design Than Giant Kafka Records
Many systems should not send large blobs through Kafka at all. Common alternatives are:
- split the data into smaller events
- store the large object in external storage
- publish a reference or object key through Kafka
For example, instead of sending a 20 MB document through Kafka, upload it to object storage and publish a message containing:
That usually scales better and avoids pushing Kafka toward roles it was not designed to serve.
A Good Troubleshooting Sequence
When you hit RecordTooLargeException, use this order:
- measure the serialized record size
- check producer
max.request.size - check broker or topic message-size limits
- check consumer fetch settings
- decide whether the message should be redesigned instead
That sequence prevents the common mistake of raising random limits without understanding which component actually failed.
Common Pitfalls
- Increasing only the producer limit and forgetting broker and consumer settings.
- Measuring the raw object size instead of the serialized record size that Kafka actually sends.
- Treating Kafka as a bulk blob transport when the message would be better stored elsewhere.
- Assuming compression removes the need for message-size discipline.
- Solving the exception without checking whether consumers can still fetch the resulting records.
Summary
- '
RecordTooLargeExceptionmeans a Kafka record exceeded one of the system's size limits.' - Producer, broker or topic, and consumer settings all have to align.
- '
max.request.sizeis important, but it is only one part of the path.' - Compression can help, but redesigning the message is often better.
- Large-message support should be an intentional architecture choice, not a last-minute config patch.
Related reading
- Kafka Producer Retry attempts
- Kafka producer send blocks indefinitely when kafka servers are down
- Kafka producer send message expiring duo to 30003 ms has passed since last append
- Kafka Producer terminating with 1 message (881 bytes) still in queue or transit
- kafka producer throw EOFException during running
- Kafka producer throws an error Invalid transition attempted from state IN_TRANSACTION to state IN_TRANSACTION
- Kafka producer throws Received unknown topic or partition error when sending to topic created via AdminClient createTopics method
- Kafka Producer TimeOutException

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.