Scrivio Interview library
ScenarioAdvanced7 min read · updated 13 November 2026

Twelve services build local stores by reading a compacted topic of 50 million customer profiles from the beginning.

A new service takes 30 hours to bootstrap, and after going live it still serves profiles that were deleted weeks ago. delete.retention.ms is at its default. Explain the cause and the design changes you would make.

A delete in a compacted topic is a tombstone, and the cleaner keeps it only for delete.retention.ms (one day by default) after cleaning it; then the tombstone and the key vanish from the log. A service that takes 30 hours to bootstrap reads a profile's old value early, but by the time it reaches the tombstone's position the tombstone has been removed, so it never sees the delete and keeps the profile forever. We set delete.retention.ms well above the slowest full bootstrap (several days), monitor bootstrap duration, make bootstraps faster with parallelism or snapshots, and make sure legal deletes reach every local store, snapshot and backup.

Why this question is asked

Using a compacted topic as a shared source of state for many services is a common and powerful pattern, and it hides a timing contract that most teams never write down: every reader must get through the whole topic faster than tombstones expire. When a slow reader breaks that contract, deleted customers come back to life in one service, which is both a correctness bug and, for personal data, a compliance problem. Interviewers ask this to see whether we can find a race between a background process and a reader. In this answer, we will recap how deletes work in a compacted topic, walk through the race, fix the configuration, speed up bootstraps, and close the gaps that matter for legal deletion.

1A Quick Recap of Deletes in a Compacted Topic

A compacted topic keeps the latest record per key. To delete a key, a producer writes a tombstone: a record with that key and a null value. When the log cleaner compacts the log, it removes all older values of that key, and keeps the tombstone so that consumers learn that the key was deleted.

It does not keep the tombstone forever, or deleted keys would still occupy space. The tombstone is kept for delete.retention.ms after the cleaning pass that first reached it, one day by default, and a later pass removes it. From then on, the log contains nothing at all for that key. A reader that starts from the beginning after that point simply never sees the key, which is correct, as long as it never saw an old value either.

2The Race That Brings Profiles Back

Now consider a bootstrap that takes 30 hours. The new service starts reading from offset 0. In hour 1 it reads an old, not yet cleaned, value of profile 4711 and stores it locally. Meanwhile, the profile was deleted weeks ago, but in this part of the log the cleaner had not yet removed the old value; or the profile is deleted during the bootstrap. Either way, there is a tombstone for 4711 further along the log.

The cleaner keeps working while the service reads. If the tombstone was cleaned at hour 2, it expires at hour 26, and a later pass removes it. The service reaches that part of the log at hour 28. The tombstone is no longer there, so the service never applies the delete, and profile 4711 stays in its store indefinitely. Nothing errors; the store is just wrong.

Step throughA 30-hour bootstrap misses a delete
New serviceCompacted topicLog cleaner
hour 1: read old value of profile 4711
store profile 4711 locally
hour 2: clean, tombstone for 4711 kept for 1 day
hour 27: tombstone expired, removed
hour 28: read the range where the tombstone was
no record for 4711
profile 4711 kept forever

7 messages in order. Play them, or step through them one at a time.

The reader saw the value before compaction removed it and reached the delete after the tombstone was gone.

3Why the Old Value Was There to Read

It is tempting to think compaction removed old values long ago, so the reader could not have seen one. But compaction is not instant or complete. The cleaner works on the clean and dirty sections at its own pace, a log is compacted only once its dirty ratio passes min.cleanable.dirty.ratio, and anything in the active segment is never compacted. And a profile deleted during the bootstrap has a perfectly valid old value earlier in the log, which the reader correctly reads before it gets to the delete.

So the guarantee of a compacted topic is only this: a reader that reaches a tombstone before it expires sees the delete. The topic does not promise anything to a reader that is slower than delete.retention.ms.

4Fixing the Configuration

The first fix is to make the contract hold: delete.retention.ms must be longer than the slowest full read of the topic, with a wide margin. With bootstraps taking 30 hours today and the topic still growing, setting it to several days, for example 7, gives room for a slow bootstrap, a restart in the middle, or an incident that delays reading. The cost is that tombstones stay in the log a few days longer, which for 50 million profiles is a small amount of disk.

Text
kafka-configs.sh --bootstrap-server b1:9092 --alter --entity-type topics \
--entity-name customer-profiles --add-config delete.retention.ms=604800000 # 7 days
# then: alert if any bootstrap takes longer than half of delete.retention.ms

Notice the alert. The setting only protects us while bootstraps stay well under it, so bootstrap duration becomes a metric we watch, with an alert at, say, half the retention. The same rule applies to a consumer that falls far behind or is stopped for days: if it is away longer than delete.retention.ms, it can miss deletes too, and the safe recovery is a fresh bootstrap.

5Making Bootstraps Faster

30 hours is also a problem on its own: recovery from a lost store takes more than a day. Several approaches help. Reading partitions in parallel, with more consumer instances or threads, scales with partition count, so a topic with too few partitions may need more. Starting from a snapshot of the store, for example a periodic dump of a healthy instance's database together with the offsets it reflects, means the new service only reads the topic from those offsets, minutes or hours of data instead of the whole history.

Another option is to load the initial state from the source of truth, such as the customer database, record the topic offsets at the time of the export, and then consume from those offsets. Any of these turns a 30-hour read into a short one, which also makes the tombstone race far less likely.

Ways to bootstrap a local store
ApproachBootstrap timeWatch out for
Read topic from offset 0grows with history (30 h)tombstone expiry, slow recovery
More partitions, parallel readersdivides by parallelismrepartitioning a keyed topic
Store snapshot plus offsetsminutes to hourssnapshot must include deletes
Load from source, then topicdepends on exportconsistent offsets at export time

6When the Deletion Is a Legal Requirement

If profiles are deleted because a customer asked for their data to be erased, the bug is not only a stale cache, it is personal data that should not exist. So the fix must make sure deletes reach every copy. Each of the twelve services' local stores must apply the tombstone; snapshots of those stores, used for faster bootstraps, must be refreshed or must have the deletes applied before being used; and any backups of the stores or of the topic must expire or be cleaned within the legal deadline.

A practical safeguard is a periodic reconciliation: compare each service's store with the source of truth and remove keys that no longer exist there. That catches any delete missed for any reason, including the race we just fixed.

7Follow-up questions

Could we avoid the problem by never removing tombstones?

Setting delete.retention.ms to a very large value effectively keeps tombstones for good. That works for correctness, but the topic then grows with every key that ever existed, and the deleted key itself, which may be personal data such as an email address, stays in the log forever. A long but finite retention, larger than any bootstrap, is the usual balance.

Is this a Kafka Streams problem too?

The same race applies to anything that builds state from a compacted topic, including Kafka Streams global tables and changelog restoration, if restoration takes longer than delete.retention.ms. Kafka Streams standby replicas and persistent local state keep restoration short, which is part of why they exist.

8Conclusion

In this answer, we saw that a tombstone in a compacted topic lives only for delete.retention.ms after cleaning, one day by default, so a reader that takes 30 hours can read an old value early and reach the tombstone's position after it was removed, keeping a deleted profile forever. We fixed it by setting delete.retention.ms well above the slowest bootstrap and alerting on bootstrap duration, made bootstraps faster with parallel reading, snapshots or a source load, and, because deletes may be legally required, made sure they reach every local store, snapshot and backup, with reconciliation as a safety net.

What to say in the interviewAbout 90 seconds aloud

Open with

The cause is a race between the bootstrap and the log cleaner. A delete in a compacted topic is a tombstone, a record with a null value, and the cleaner keeps it only for delete.retention.ms after cleaning it, which is one day by default; after that the tombstone and the key are gone from the log.

Then, if they want more

The new service reads from offset 0 for 30 hours. Early on it reads an old value of a profile that was later deleted, and stores it.

By the time it reaches the part of the log where the tombstone was, more than a day has passed, the tombstone has been removed, and the service never learns about the delete, so it serves that profile forever. The fix has three parts.

First, set delete.retention.ms well above the slowest full bootstrap, for example seven days, and alert if any bootstrap takes more than about half of that; the same applies to consumers that stop for days.

Second, make bootstraps much faster: more partitions read in parallel, starting from a snapshot of a healthy store with its offsets, or loading from the source of truth and then reading from known offsets.

Third, since these are customer deletes and possibly legal ones, make sure deletes reach every copy, meaning the local stores, their snapshots and any backups, and add a periodic reconciliation against the source of truth to catch anything missed.

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 "A new service takes 30 hours to bootstrap, and after going live it still serves profiles...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-internals/50dff0aff3/