Quick revision
The short answer
Each scanned file goes to object storage such as S3 under an immutable key, and only after it is durably stored do we publish a small Kafka event, keyed by customer id, with the reference, size, checksum and content type. Consumers fetch and verify the file, retry a missing object a limited number of times and then dead-letter it. Object lifecycles are aligned with topic retention and the 30-day audit, access is controlled per service, and Kafka carries kilobytes while about 10 TB a day sits in storage built for it.
What to remember
In this answer, we sized the pipeline at roughly 10 TB a day and saw why the files belong in object storage while Kafka carries small events keyed by customer id. We store each file under an immutable key and publish only after it is durable, verify checksums on read, retry missing objects with a limit and then dead-letter them, align object lifecycles with topic retention and the 30-day audit, make legal deletion remove the object, and secure access per service so an event alone grants nothing.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Each scanned file goes to object storage such as S3 under an immutable key, and only after it is durably stored do we publish a small Kafka event, keyed by customer id, with the reference, size, checksum and content type. Consumers fetch and verify the file, retry a missing object a limited number of times and then dead-letter it. Object lifecycles are aligned with topic retention and the 30-day audit, access is controlled per service, and Kafka carries kilobytes while about 10 TB a day sits in storage built for it.
Why this question is asked
Passing large files between services is a classic place where Kafka is misused. Putting 50 MB files into records strains brokers, consumers and retention, while not using Kafka at all loses ordering and replay. The claim-check pattern, named after the ticket you get at a cloakroom, keeps the best of both. Interviewers ask this design to see whether we can size it, get the ordering of writes right, and think about deletion and security, not just draw boxes. In this answer, we will do the numbers, design the event and storage layout, walk through the write and read paths, handle failures, align lifecycles and secure access.
1Sizing the Problem
200,000 files a day at an average of about 50 MB is roughly 10 TB a day. Spread evenly that is about 2.3 files and 115 MB per second, with peaks several times higher. Kept for 30 days, that is around 300 TB of original files, before any derived outputs from the five stages.
Putting that through Kafka would mean raising every size limit, replicating 10 TB a day three times across brokers, and keeping 900 TB of replicated log for the audit period. Object storage holds the same 300 TB with built-in durability at a small fraction of the cost, while Kafka carries 200,000 events of about 1 KB each, roughly 200 MB a day. Chunking files into many records would be worse still: the chunks of one file must stay together and in order, retries and dead-lettering would act on pieces, and retention could delete half a file.
2The Event and the Storage Layout
Each file is stored once under an immutable key, either a UUID or the SHA-256 of its content. A content hash has a nice property: uploading the same scan twice produces the same key, so duplicates cost nothing. Stages never overwrite an object; a stage that produces a new version, such as an OCR result or a redacted copy, writes a new object and publishes a new event that points to it.
The event is keyed by customer id, so all of a customer's documents go to one partition and are processed in order, which is the ordering the business asked for.
3Write First, Publish Second
The order of the two writes is the heart of the pattern. The producer uploads the file (a multipart upload for files this size), waits for the store to confirm, and only then publishes the event. If it did the reverse, a fast consumer could receive an event for an object that does not exist yet, or that never will if the upload fails.
The opposite failure, upload succeeded but publish failed, leaves an orphan object. That is harmless for correctness, and a periodic job or a lifecycle rule on a staging prefix cleans it up. If the upload is triggered by a database transaction, an outbox table makes the publish reliable.
8 messages in order. Play them, or step through them one at a time.
4Failure Handling on the Consumer
A consumer fetches the object and verifies the checksum before doing anything else, which catches truncated downloads and wrong references. A missing object is treated as a retriable error, with backoff and a limit, for example five attempts over ten minutes; with S3's strong read-after-write consistency a missing object usually means a real problem rather than a delay, so the limit can be short. After the limit, the event goes to a dead-letter topic with the reason in headers, and the partition keeps moving.
Processing must be idempotent, because offsets are committed after the work and a crash causes redelivery. Writing derived objects under deterministic keys, such as the source hash plus the stage name, makes a repeated run produce the same object rather than a duplicate.
5Lifecycles, Deletion and the Audit Trail
The event and the object must live at least as long as each other is needed. If the topic keeps events 30 days for the audit trail, objects must be kept at least 30 days plus a margin, enforced by a lifecycle rule on the bucket; otherwise a replay finds references to deleted files. Older objects can move to a cheaper storage class after a week.
Legal deletion, such as a customer's erasure request, must delete the object, which is the place the personal data really lives. The events then hold a reference to nothing, and consumers treat a deleted document as a terminal state, not an error to retry. Because the event itself carries no document content, deleting the object is usually enough to honour the request.
| Item | Store | Retention | Size per day |
|---|---|---|---|
| Scanned files and stage outputs | Object storage | 30 days plus margin, then expire | about 10 TB plus outputs |
| Events with references | Kafka, keyed by customer | 30 days (audit) | about 200 MB |
| Failed events | Dead-letter topic | 30 days, reviewed daily | small |
6Securing the Objects
A reference in an event must not be enough to read a customer's document. Each service gets its own credentials with a policy that allows only the prefixes it needs, for example the OCR service may read docs-raw and write docs-ocr. Objects are encrypted at rest with managed keys. If a service outside the cloud account needs a file, it receives a short-lived signed URL, valid for minutes, not a permanent link. That way a leaked topic exposes ids and checksums, not documents.
7Follow-up questions
Why not put the signed URL in the event?
A signed URL expires, often within minutes, while events may be replayed days later, and anyone reading the topic could use a valid one. Store the stable reference in the event and let each consumer create access with its own credentials.
How do you keep per-customer ordering if one file takes much longer to process?
Keying by customer id keeps the events of one customer in one partition, and the consumer processes them in order. A slow file delays that customer's next document, which is the price of ordering; other customers on other lanes are unaffected if we process by key in parallel.
What if the object store is down?
Producers cannot store files, so they buffer or fail the upload and publish nothing, and consumers retry fetches with backoff and pause their partitions rather than dead-lettering everything. The topic simply waits; nothing is lost.
8Conclusion
In this answer, we sized the pipeline at roughly 10 TB a day and saw why the files belong in object storage while Kafka carries small events keyed by customer id. We store each file under an immutable key and publish only after it is durable, verify checksums on read, retry missing objects with a limit and then dead-letter them, align object lifecycles with topic retention and the 30-day audit, make legal deletion remove the object, and secure access per service so an event alone grants nothing.
Open with
I would use the claim-check pattern. The numbers decide it: 200,000 files at about 50 MB is roughly 10 TB a day and 300 TB over the 30-day audit, which is cheap and natural in object storage and painful in Kafka with replication.
Then, if they want more
So each file goes to S3 or similar under an immutable key, ideally its SHA-256, and only after the upload is confirmed do we publish a small event with the reference, size, checksum and content type, keyed by customer id for per-customer ordering.
Writing first and publishing second means a consumer never sees a reference to a missing file; an orphan from a failed publish is cleaned up by a lifecycle rule. Each consumer fetches the object, verifies the checksum, treats a missing object as retriable with a short limit and then dead-letters it, and processing is idempotent because of redelivery.
Stages write new objects rather than overwriting. Object retention is at least the topic retention and the audit period, and legal deletion removes the object, which is where the data lives. Each service has its own scoped credentials, objects are encrypted at rest, and external access uses short-lived signed URLs, so the event alone grants nothing.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design it with Kafka using the claim-check pattern, covering storage, lifecycle...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-clients-in-depth/0b51d7c375/