Distinguish logical deletion from physical reclamation and verify that a compacted generation preserves current access rules.
Retrieval tombstones: compact indexes without reviving deleted evidence
Deletion has two clocks
A source can be removed from search results before its bytes are physically reclaimed. A logical tombstone marks it ineligible; segment merge or full index rebuild later removes obsolete postings and vector entries. A privacy or compliance request cannot wait for compaction before stopping disclosure. Enforce deletion in the authoritative eligibility layer immediately, then track physical reclamation under a separate deadline. Document lifecycle defines the access decision; compaction changes storage and performance, not the authority of that decision.
Rebuild from authoritative live records
A compactor must read a consistent source snapshot plus all later delete and update events up to a recorded watermark. Copying only old index entries can revive a document that was deleted while the build ran. Stable document IDs and revision numbers make replay idempotent. When the candidate generation catches up, compare its active-ID set against the authoritative source and tombstone ledger before traffic moves. Ingestion delete races explain why event order and repeated deliveries must be accounted for.
Graph and lexical cleanup are different operations
An inverted index may retain deleted postings until a segment merge. An ANN graph can retain unreachable or masked nodes and may need a backend-specific rebuild to recover memory and search quality. Do not assume an index force-merge command handles vector graph layout exactly as it handles text postings. Measure deleted-record ratio, storage bytes, candidate visits and recall on an exact baseline before scheduling maintenance. HNSW recall curves can show whether stale graph structure affects retrieval.
Cut over with a deletion proof
A new compacted generation is not ready because its build job succeeded. It must pass source-count checks, sampled document hashes, permission tests, delete proofs and a freshness watermark. Pin in-flight requests, then switch the serving pointer to the verified generation. Retain rollback only if the old generation still applies current tombstones and access filters. Alias cutovers describe the pointer operation; the deletion proof guards what that pointer exposes.
Schedule physical work without hiding failures
Merge or rebuild work consumes I/O, CPU and temporary disk. Running it on every delete can harm ingestion and p95 query latency; never running it can inflate storage and graph traversal. Set thresholds from measured delete ratio, disk headroom and latency, and keep a separate deadline for permanent erasure when required. If a build fails halfway, keep the current serving generation and its tombstone filter. Observability should report both eligibility latency and bytes remaining, because a zero-result query does not prove physical deletion.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class SourceRevision:
document_id: str
revision: int
text: str
def compact(source_rows: list[SourceRevision],
deleted_ids: set[str]) -> dict[str, SourceRevision]:
active = {}
for row in source_rows:
if row.document_id in deleted_ids:
continue
current = active.get(row.document_id)
if current is None or row.revision > current.revision:
active[row.document_id] = row
assert not active.keys() & deleted_ids
return active
history = [SourceRevision("pump-p47", 1, "old seal rule"),
SourceRevision("pump-p47", 2, "current seal rule"),
SourceRevision("private-plan", 1, "restricted plan")]
generation = compact(history, {"private-plan"})
assert generation["pump-p47"].revision == 2
assert "private-plan" not in generationPerformance and operating cost
Scanning R source revisions takes O(R) time and O(D) memory for D retained documents; writing a real index adds tokenization, embedding, posting and graph-build costs. A tombstone lookup can be near constant time with a suitable set, but maintaining it across every serving path has operational cost. The example assumes one authoritative delete set at a fixed snapshot. A production build must replay later changes and verify a watermark before cutover; physical byte removal depends on the backend's storage lifecycle.
Common Mistakes
- Waiting for physical compaction before suppressing a deleted document in search.
- Building from stale source snapshots without replaying newer tombstones.
- Assuming a clean query result proves the underlying bytes were erased.
- Rolling back to a generation that lacks current deletion and permission filters.
Validation drill
Create 123 source revisions, delete eight during a rebuild and replay out-of-order updates. Compare active IDs with the authoritative ledger before and after cutover; inspect disk bytes and top-12 recall separately.
