Sooner or later someone asks to put a PDF, an image, or a 20 MB JSON document on a Kafka topic. The default answer is "don't", but the real answer is a decision about where the bytes live. This note covers the size limits that apply at each hop, why raising them is more expensive than it looks, and the claim-check pattern most teams end up with.
The limits are per hop, and they have to agree
A record has to clear several independent settings. If you raise one and forget another, you get an error from the hop you forgot.
- Producer:
max.request.size(default 1 MiB) caps the size of a request, and in practice the largest record batch you can send. - Broker / topic:
message.max.bytesis the broker-wide limit on the largest record batch. The topic-level override ismax.message.bytes. Prefer the topic override, so one oversized-payload topic does not change the rules for the whole cluster. - Replication:
replica.fetch.max.bytesshould be at least as large as the biggest batch. Modern brokers will still return the first oversized batch to a follower, but a mismatch here is a classic source of confusing replication behavior, so keep the values consistent. - Consumer:
max.partition.fetch.bytesandfetch.max.bytesbound fetch responses. Since KIP-74 the consumer will still return a first batch that exceeds them, so they act as soft limits. Do not rely on them to protect your heap.
Two details cause repeated confusion. The broker limit applies to the batch as stored, which is after compression, so a compressible payload can fit under a limit its raw size would exceed. And a managed service may fix or restrict some of these settings, so check your MSK or Confluent configuration before designing around a number.
What a large record costs
Raising limits works mechanically, and the cost shows up elsewhere:
- Memory. Producers buffer whole batches in
buffer.memory, and consumers hold fetched batches in the heap. With many partitions per consumer, the fetch sizes multiply. Size heaps formax.partition.fetch.bytes × assigned partitions, not for the average record. - Latency for everyone else. A single partition's log is read sequentially. A large record delays smaller records behind it, and a slow consumer on a large-record topic builds lag in bytes much faster than in record count. Alert on time lag rather than record count.
- Replication and page cache. Large batches fill the page cache quickly and push out the hot tail that normal consumers read. Catch-up reads then hit disk. If the large-payload topic shares brokers with latency-sensitive topics, expect interference, and see the quota and noisy-neighbor considerations in our multi-tenancy note.
- Retention arithmetic. Seven days at a few records a second is trivial when records are 2 KB, and several terabytes when they are 5 MB. Redo capacity planning with measured bytes per second.
The claim-check pattern
The usual alternative is to store the payload in object storage and publish only a small record that points to it.
A reasonable record carries:
- A URI (bucket and key), with a version ID if the bucket is versioned.
- The payload size and a content hash (SHA-256), so a consumer can verify what it fetched.
- The content type and, if relevant, the schema ID of the payload.
- The business metadata that consumers filter on, so most of them never fetch the blob.
The ordering of operations matters:
- Write the blob first, then produce the record. If the producer crashes between the two steps, you have an orphaned object, which is cheap and harmless. The reverse leaves a record pointing at nothing.
- Use content-addressed or unique keys. Retried producer sends then cannot overwrite an object a consumer is reading. The key should be deterministic from the content or generated once per logical message, not per attempt.
- Sweep orphans. A lifecycle rule or periodic job removes objects that no record references after a grace period longer than your maximum producer retry window.
Be honest about what you give up. Kafka's guarantees cover the pointer, not the blob. Exactly-once semantics do not extend to the object store, so consumers need to be idempotent about fetching and processing. Access control now lives in two places, and a consumer authorized on the topic also needs read access to the bucket. Replicating the topic with MirrorMaker 2 replicates the pointer and not the object, so a disaster-recovery cluster needs cross-region bucket replication too, with the URI scheme designed to survive that.
Retention and compaction must line up
The object's lifetime has to cover the record's lifetime, with margin. On a delete-retention topic, set the bucket lifecycle expiry comfortably longer than retention.ms, including the time a consumer might spend replaying after an outage. On a compacted topic the record can live indefinitely, so the object cannot be expired by age. Deleting a key with a tombstone should trigger a deliberate cleanup of the referenced object, which is a job your pipeline has to own. Also decide how your privacy obligations (deletion requests, for example) apply to blobs, since they will not disappear when the record does.
When chunking is the better answer
Splitting a payload into chunks of, say, 256 KB on the same topic avoids a second system. It costs you in other ways: all chunks must share a key so they land in one partition in order, consumers must reassemble them and handle partial sequences after rebalances, and a lost or expired chunk silently corrupts the message. It can work for occasional payloads of a few megabytes in a closed system. We rarely recommend it above that, and for payloads in the tens of megabytes we recommend the claim check.
A decision rule
- Payloads under about 1 MiB compressed: leave the defaults alone and keep them off the cluster's critical path with compression (
lz4orzstd). - Occasionally up to a few MiB: raise the limits on one dedicated topic, tune consumer fetch sizes and heap, and watch time lag.
- Regularly larger, or highly variable: claim check, with checksums, ordered writes, orphan sweeps, and aligned retention.
Checklist before you ship
- Limits raised consistently on the producer, topic, replica fetch, and consumer, and tested with a record at the maximum size.
- Heap sized for fetch size times assigned partitions.
- Capacity plan redone in measured bytes per second.
- Claim-check writes ordered blob-first, with keys safe under retries.
- Bucket lifecycle and topic retention reviewed together, including the DR region.
- Time-lag alerting on the large-payload consumer group.
If you are weighing one of these designs against a specific cluster, a Kafka Health Check covers the broker and client limits, and the architecture work is part of Streaming Architecture & Build.