Kafka large-message offloading with kaf-s3
A document, binary export or large JSON payload can be a poor fit for a Kafka record. Raising the broker limit is one option, but it also changes the resource demands on producers, brokers and consumers. Another option is to keep the bytes in object storage and use Kafka to carry the reference.
That is the job of kaf-s3. This page explains the architecture and the decisions around it. The current repository README is the source for the library behaviour described below; this page does not claim a new deployment test or a measured performance gain.
Offloading is not the same as a sink
A Kafka-to-S3 sink normally consumes topic records and writes them to object storage for later use. kaf-s3 changes the producer and consumer path for an individual payload. Applications using its consumer get the original bytes back after retrieval and checks.
If the requirement is to export existing topics as files for Athena, Iceberg or another analytical reader, evaluate a sink or ingestion job instead. A bucket full of claim-check payloads is not automatically a queryable table.
How the reference path works
- The producer sends payloads at or below its configured inline threshold to Kafka unchanged.
- For larger payloads, it uploads the bytes to the configured S3 bucket. The key is random by default; content-based keys are an option.
- It publishes a JSON reference carrying the bucket, key, checksum and compression information.
- The consumer recognises the reference, checks the allowed bucket and prefix, downloads under its size cap and checks integrity before returning the bytes.
The README documents SHA-256 verification, usable ETags and rejection of references without a verifiable checksum by default. Multipart ETags are not treated as ordinary content hashes. The download and gzip expansion are bounded by the configured payload cap.
What the application still owns
This design adds an object-store request to the consumer path. A Kafka reference can remain readable longer than the object it points to. Permissions can also permit one hop and deny the next. Treat both as ordinary failure cases.
- Retention. Keep objects long enough for replay, delayed consumers and every consumer group that needs them.
- Cleanup. Prefer a deliberate lifecycle policy. Deleting after one consumer reads an object can break another group or a later replay.
- Credentials. Use the supported credential chain and scoped roles. Do not place access secrets in payloads or examples.
- Failures. Monitor missing objects, checksum failures, permissions and publish failures separately.
- Size. Set a cap the consumer can afford. Offloading does not make unlimited payloads safe.
The producer's rollback on a failed Kafka publish is useful, but it does not turn two independent systems into one transaction. Plan for uncertain outcomes and cleanup rather than assuming every crash leaves a perfect pair of records.
When this design earns its place
It can suit documents, exported files and other payloads whose bytes need to travel with an event without sitting in the Kafka log itself. It is less attractive when an existing durable object already has a stable identifier, or when a normal small record is enough.
For configuration, local setup, integrity, cleanup and deployment details, read Kafka to S3 for large messages with kaf-s3. Keep that implementation guide beside the current README. For the wider destination design, read the ingestion architecture guide.
If you need a second pair of eyes on the design, see my consulting services or contact me.