# org.apache.kafka.common.errors.RecordTooLargeException: The request included a message larger than the max message size the server will accept.

- **ID:** `kafka/max-message-bytes-exceeded`
- **Domain:** kafka
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A producer sent a message that exceeds the broker's max.message.bytes or the topic's max.message.bytes configuration, causing the broker to reject it.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Kafka 2.8.0 | active | — | — |
| Kafka 3.0.0 | active | — | — |
| Kafka 3.4.0 | active | — | — |
| Kafka 3.6.0 | active | — | — |

## Workarounds

1. **Increase the broker's max.message.bytes in server.properties and the topic's max.message.bytes if overridden:

# server.properties
max.message.bytes=10485760  # 10 MB

# Topic override
alter topic my_topic --config max.message.bytes=10485760

Also increase the producer's max.request.size to match:
Properties props = new Properties();
props.put("max.request.size", 10485760);** (90% success)
   ```
   Increase the broker's max.message.bytes in server.properties and the topic's max.message.bytes if overridden:

# server.properties
max.message.bytes=10485760  # 10 MB

# Topic override
alter topic my_topic --config max.message.bytes=10485760

Also increase the producer's max.request.size to match:
Properties props = new Properties();
props.put("max.request.size", 10485760);
   ```
2. **Split large messages into smaller chunks at the application level before sending, and reassemble on the consumer side. For example, use a message chunking library or implement custom logic.** (85% success)
   ```
   Split large messages into smaller chunks at the application level before sending, and reassemble on the consumer side. For example, use a message chunking library or implement custom logic.
   ```

## Dead Ends

- **Increase the producer's max.request.size only** — max.request.size controls the client-side buffer, but the broker's max.message.bytes still blocks the message; both must be increased. (80% fail)
- **Set the message compression to gzip** — Compression reduces size but does not guarantee the compressed message will be under the limit; large uncompressed data may still exceed it. (70% fail)
