On a stream that keeps only the latest value per key, how is a key removed entirely, and why must that record linger?
answer
- a delete is itself a write
- valueless record, same key
- it must outlive the value
- grace period versus the slowest rebuild
- a missed marker resurrects the key
basics
~20 sYou append a valueless record under that key — a deletion marker — which supersedes the value and tells every reader the key is gone. The marker must then survive a grace period long enough for the slowest full pass over the history to reach it, or that reader resurrects the key.
solid answer
~50 sAn append-only store has no way to take a record out on request, so removing a key is itself a write: a valueless record under that key, a deletion marker. It supersedes the value exactly as any newer record would, so the removal pass drops the old value — and every reader that crosses the marker learns to drop the key from whatever state it keeps. The marker cannot go at the same time as the value, because a reader that has not reached it yet would be left holding a value the store no longer has. So the marker itself survives for a bounded grace period before it becomes removable. That grace period is a contract with the readers: it must outlive the slowest full pass over the history. A reader whose pass takes longer reads the value early on, finds the marker already gone when it arrives, and resurrects a key it should have dropped.
go deeper
Recall the shape: on a store that only appends, removing a key means writing a record with that key and no value. It is a write, not a delete.
Explain the two jobs the marker does — superseding the value for the store, and telling readers to drop the key — and why the second forces it to survive after the first is finished.
Size the grace period from the slowest full pass over the history on a bad day, and recognise a resurrected key in the wild as a reader that read the value and missed the marker.
Treat the grace period as a published contract for a shared stream: it bounds how slow any reader of it may be, and it is not free, because markers that never expire accumulate one per key ever deleted.
## Deleting from a store that only appends On a store that keeps only the latest value per key, there is no delete operation in the ordinary sense: the history is appended to, never edited. Removal of a key is expressed the only way anything is expressed here — as a write. The writer appends a **deletion marker**: a record carrying the key and no value. That single mechanism does two jobs at once: - **For the store.** The marker is the newest record for that key, so under keyed retention it supersedes the value, and the next removal pass over that region discards the value. - **For the readers.** Every reader that crosses the marker in the history learns that the key is gone, and drops it from whatever copy of the latest value it maintains. A reader has no other way to find out; an absent record is indistinguishable from a record it has not reached yet. The second job is the one that constrains the design, and it is the reason the marker cannot simply vanish along with the value it replaced. ## Why the marker outlives the value If the marker were removed at the same moment as the value, a reader that had already read the value but had not yet reached the marker's place in the history would never be told. It would keep the key forever, with a value the store has forgotten — and no future pass over the stream would correct it, because there would be nothing left to read. So the marker is given a **grace period**: a bounded span during which it is deliberately kept even though it is itself removable, precisely so that readers still working through the history can cross it. After that, the marker is removed too, and the key leaves the stream without a trace. That makes the grace period a contract, and it is worth stating in one sentence: **the marker's grace period must outlive the slowest full pass over the history that needs to see it.** ## The failure, step by step When the contract is broken, the symptom is a deleted entity coming back to life. The sequence: 1. A reader begins a full pass over the stream — a rebuild of its own copy of the latest value per key — starting at the earliest position still on the store. Early in the pass it reads the current value for key *K*. 2. Meanwhile the writer appends a deletion marker for *K*. 3. The removal pass runs over that region: the old value of *K* is discarded, and the marker remains. 4. The grace period expires. A later pass removes the marker as well. There is now nothing about *K* anywhere in the stream. 5. The slow reader finally reaches that part of the history — and crosses nothing. It never learns about the delete. 6. Its rebuilt state contains *K*, with a value that no longer exists anywhere in the store. The delete has been undone, silently, by a reader. Nothing in that sequence is a bug in the store. Every step did exactly what it promised; the grace period was simply set shorter than the rebuild it had to cover. ## Sizing it, and the alternatives The grace period is not a number to leave at whatever the platform ships. Size it from the real quantity: how long the slowest consumer of this stream takes to work through the whole history, measured on a bad day rather than a good one — a cold rebuild on a loaded cluster, not a warm one. Then leave margin, because rebuilds get slower as the stream grows. | Approach | What it costs | When it is the right call | |---|---|---| | A deletion marker with a grace period sized from the slowest full pass | the operator has to know that number and re-check it as the stream grows | the default; it is the mechanism the store offers | | A value carrying an explicit deleted flag, with no valueless record at all | the key and its value never leave the store, so the floor never comes down | when deletes are rare and readers vary wildly in speed | | Sizing rebuilds down so no pass can outlive the grace period | engineering effort on the reader side, and it must hold as the stream grows | when the stream is shared and you cannot police every reader | Two cautions worth carrying. First, designs genuinely differ: some platforms give the marker a bounded survival of its own, separate from any other bound; others tie it to the general removal schedule; a store that removes a record on acknowledgement has no such concept at all, because there is no standing state to correct. Ask which one you are on rather than assuming. Second, the marker only reaches readers that actually read the stream. Any copy of this data maintained by some other route — a nightly export, a hand-loaded table — is not covered by the marker at all, and that gap is a design problem, not a retention setting.
- What does the symptom of a grace period that is too short look like in production?A deleted entity that reappears in one downstream view and not in others, usually after a rebuild rather than in steady operation. The store has no record of the key at all, which is the giveaway: the resurrected value can only have come from a reader that read it before the marker went and never crossed the marker.
- Can the grace period be made effectively unlimited to be safe?It can be made long, but not free. Markers that are never removed accumulate one per deleted key forever, so a stream with heavy key turnover ends up storing a permanent record of everything that ever existed. The honest sizing is the slowest full pass plus margin, re-checked as the stream grows.
- Does a reader that starts fresh after the marker has been removed have a problem?No. Once both the value and the marker are gone, a reader starting from the earliest position still on the store never sees the key and correctly ends up without it. The hazard is only for a reader that read the value while it still existed and then missed the marker.
A shared address book where entries can only be added at the end. To retire an address you cannot erase it; you add a note saying 'no longer valid'. The note has to stay pinned up until everyone who keeps a private copy has read that far — take it down early and the slow copiers keep the old address forever.
saying these in an interview costs you the question
- Thinks a key can be removed by asking the store to delete a record
- Says the marker can be discarded as soon as the old value is gone
- Treats the grace period as a default nobody needs to size
- Explains a resurrected key as a bug in the store rather than a missed marker
- Assumes every platform in this class has markers at all
- Believes a reader can notice a key is gone by its absence alone