• Home
  • Server Management
  • Home
  • Server Management
home/Knowledge Base/Kafka/Fixing “The message is too large” Error in Apache Kafka: A Step-by-Step Guide

Fixing “The message is too large” Error in Apache Kafka: A Step-by-Step Guide

4 views 0 May 7, 2025 admin

If you’ve encountered the dreaded RecordTooLargeException or The message is too large error in Apache Kafka, you’re not alone. This common issue can break data pipelines and confuse new users — but the fix is usually straightforward.

In this blog post, we’ll walk through why this happens and how to solve it step-by-step from both producer and broker sides.


🧠 Why This Happens

Kafka imposes limits on message size at several layers:

  • Producer config: max.request.size
  • Broker config: message.max.bytes
  • Topic config: max.message.bytes

When a message exceeds any of these thresholds, Kafka throws a RecordTooLargeException.


🛠️ Step-by-Step Solution

1. Increase Producer Max Request Size

Update your producer client config:

javaCopyEditProperties props = new Properties();
props.put("max.request.size", 10485760); // 10MB

Or in a YAML config (if using Kafka Connect):

max.request.size: 10485760

Tip: Start with 5-10 MB and increase only if necessary.


2. Check and Update Broker Config

Edit your server.properties on the Kafka broker:

propertiesCopyEditmessage.max.bytes=10485760

This must be equal or higher than the producer’s max.request.size.

Don’t forget to restart the broker after changing this.


3. Update Topic Config (Optional)

If a specific topic needs larger messages:

kafka-configs.sh --bootstrap-server <broker>:9092 \
--entity-type topics --entity-name your-topic \
--alter --add-config max.message.bytes=10485760

This allows flexibility: most topics can stay small, while selected ones allow big payloads.


4. Compress Your Messages

Compression drastically reduces message size. Supported algorithms:

  • gzip
  • snappy
  • lz4
  • zstd (Kafka 2.1+)

Producer example:

props.put("compression.type", "snappy");

Note: Compression happens on the client-side.


Common Pitfalls

  • Setting broker values lower than the producer’s leads to failures.
  • Don’t forget about schema overhead (e.g., in Avro/Protobuf).
  • Monitor broker memory and disk — large messages can affect performance.

🔍 Useful Metrics to Monitor

  • BytesInPerSec / BytesOutPerSec (per topic)
  • RequestSizes
  • Broker heap usage

Tools like Prometheus + Grafana can help visualize these.


Conclusion

Kafka is highly performant — but large messages need careful handling. If you follow the steps above and set proper limits, your pipeline will run smoothly without bloating or crashing.

If you’re constantly sending large payloads, consider:

  • Breaking messages into chunks
  • Using Kafka Streams or ksqlDB for transformation
  • Offloading binary data (e.g., to S3) and sending only metadata in Kafka
Tags:Kafka message too largekafka

Was this helpful?

Yes  No
Related Articles
  • Kafka Broker Keeps Restarting? Common Causes and Solutions
  • Kafka “Leader Not Available” Error: Root Causes and Fixes
  • Kafka Retention Policy Not Working? Here’s What to Check
  • Kafka Consumer Lag Explained: What It Is and How to Fix It

Didn't find your answer? Contact Us

Leave A Comment Cancel reply

Kafka
  • Fixing “The message is too large” Error in Apache Kafka: A Step-by-Step Guide
  • Kafka Consumer Lag Explained: What It Is and How to Fix It
  • Kafka Retention Policy Not Working? Here’s What to Check
  • Kafka “Leader Not Available” Error: Root Causes and Fixes
  • Kafka Broker Keeps Restarting? Common Causes and Solutions
All Categories
  • Grafana
  • Kubernetes
  • Kafka
  • Nginx
  • Linux
  • MySQL

Kafka Consumer Lag Explained: What It Is and How to Fix It  

Manual
  • We we are
  • Contact us
  • Suppliers
Support
  • Live chat
  • Knowledge Base
  • Blog
Security
  • Report Copyright
  • Trademark
  • Security Issue
Manual Head Office
Phone : 765 987-7765
Toll free : 1 999 654-98729
Fax : 250 684-29865
Emergency Help Desk: 7pm-2pm

Center street, 18th floor, New York, NY 1007