The interview problem
A document platform stores immutable blobs separately from transactional document metadata. Failed uploads and deleted document versions leave unused blobs. Design garbage collection for one billion objects while uploads, restores and new references continue. Show why yesterday's unreferenced-object list is insufficient authority to delete an object today.
Original system-design practice, not a reported company interview. Object counts, durations and rates are hypothetical. Primary technical reference retrieved September 27, 2026.
1. Define every reason an object is still live
Roots include current document versions, retained historical versions, active upload reservations, snapshot/export leases and explicit retention holds. A blob referenced only by an old version is still live until that version's retention expires. Removing a UI document does not necessarily remove every root.
Use immutable physical object identities, including storage generation or version when applicable. A content hash may identify equivalent bytes, but deleting an old generation must never delete a newly uploaded replacement with the same logical hash. All reference creation must pass through a controlled metadata API.
For this design, keep each tenant's object registry and root-edge records in the same transactional metadata domain. Cross-tenant deduplication is excluded initially; it would require coordinating roots and permissions across that boundary. Safety means never deleting a generation needed by a valid root, not merely minimizing garbage age.
2. Make reference publication and deletion compete atomically
Use an object registry with generation, lifecycle state, last mutation version, retention deadline and upload reservation. Root-edge records identify what retains each object. States include uploading, available, candidate, deleting and deleted. An upload registers a reservation before writing bytes, then verifies completion before publication.
Creating a root locks the registry entry, checks that the generation is available or recoverably marked as a candidate, and inserts the edge in the same transaction. Adding a root to a candidate clears its candidate status and advances the mutation version. A generation already in deleting state cannot gain new roots; the caller must recover a valid copy under a new generation or fail.
A sweep worker also locks that entry. It may transition candidate to deleting only after rechecking current roots, reservations, leases and retention in the authoritative metadata store. That transition and the root check are serialized with reference creation. A scan result or a cached reference count alone is not sufficient.
All paths must honor this protocol: restore, sharing, version creation, export and maintenance jobs. If reference writes bypass it, a later reconciliation job cannot restore bytes already deleted.
3. Use mark scans to find candidates
Run a consistent metadata scan of retained roots and their referenced generations. For nested manifests, traverse the full reachable graph, not just direct document pointers. In this design, a manifest builder registers child-retention edges through the same registry protocol before publishing the parent. Keep those edges until parent deletion is irrevocable; removing them afterward may delay child reclamation but cannot expose a live child. A new parent reference therefore cannot make unprotected descendants reachable behind the sweep. Generate candidate IDs that are old enough and absent from the mark set, with the scan epoch and observed mutation version attached.
The mark phase narrows work; it is not the deletion authority. Reference changes after its snapshot are resolved by the transactional final check. If roots are distributed across systems without a shared transaction boundary, use a proven barrier, lease or epoch protocol that covers every publisher; do not assume this local design applies unchanged.
A grace period protects against delayed inventory and abandoned uploads, but time alone cannot prove that no publisher will later use a blob. Upload reservations have bounded leases. Expired publishers must fail publication or obtain a fresh valid reservation. Fence upload finalization against reservation expiry, using a controlled completion service or equivalent storage enforcement. A resumed multipart upload must not recreate an already deleted generation behind the collector; late bytes that cannot be prevented need a separate orphan sweep and must never gain roots.
4. Trace the stale-sweep race
At 10:00, a mark scan finds blob B with no roots and records mutation version 7. At 10:05, a document restore transaction locks B, adds a root, clears its candidate status and advances the version to 8. At 10:10, the sweep attempts deletion using version 7.
The stale conditional transition fails. Even if the worker refreshes its version, the current root check prevents deletion. A simple script that trusts the 10:00 list would delete a live blob.
Reverse the order: at 10:04 the sweep successfully changes B to deleting after proving no roots remain. The restore arrives at 10:05 and is rejected for that generation. It may restore from a retained backup into a new generation, but it cannot publish a pointer to B while deletion is underway. The serial order determines which operation wins.
After physical deletion, mark the registry generation deleted. If the delete response is lost, retry against that exact immutable generation. Keep a tombstone long enough to reject stale publishers and retries; reusing the same physical key without version protection creates an ABA-style deletion hazard.
5. Protect readers and restores
Readers that require an object to survive beyond metadata lookup need a bounded pin or lease acquired through the same root protocol before its last ordinary reference disappears. Existing retained snapshot roots may provide this protection. Define lease renewal and expiry; an indefinitely paused reader cannot retain data forever without an explicit policy.
A read URL alone is not a collector-visible root unless issuance registers the required retention interval. If the system promises a URL remains usable for an hour, collector policy must honor that promise or the API must document weaker behavior.
A metadata backup that refers to old object generations also creates a recovery obligation. Either retain those objects for its restore horizon or back up their bytes independently. Restoring old metadata without restoring its referenced blobs yields a logically valid database full of broken pointers.
6. Budget scans and reclamation delay
For one billion registry entries at an assumed 128 bytes of scan input each, a full pass reads 128 GB before indexes and replication. At an effective aggregate rate of 200,000 entries/s, scanning takes 5,000 seconds, about 83.3 minutes. Root traversal and candidate validation add separate work.
Suppose objects become eligible 24 hours after their last root is removed, scans start every six hours, and a scan takes at most 90 minutes. If eligibility occurs just after a scan begins, discovery can take up to about 31.5 hours from root removal: 24 + 6 + 1.5. A delete queue adds further delay, and active leases or new roots can postpone deletion indefinitely.
At ten million newly unreachable objects/day and 50 KB per object, garbage accumulates at 500 GB/day. A steady two-day reclamation delay corresponds to roughly 1 TB awaiting collection, assuming stable rates and no additional retained roots. This is retained garbage, not total live storage.
If five million physical deletions are ready and the permitted rate is 1,000/s, ideal queue drain takes 5,000 seconds, about 83.3 minutes. Include retry traffic and object-store limits in capacity tests; keep per-tenant fairness so one large cleanup does not monopolize the collector.
7. Fail conservatively and expose evidence
On unavailable metadata, ambiguous root enumeration or inconsistent lifecycle state, stop deletion for the affected scope. A temporary storage leak is preferable to guessing that missing metadata means an orphan. Candidate retention can grow while the integrity issue is investigated.
Dry-run a new collector against representative tenants and record why each candidate is considered unreachable. Cap deletion batches and monitor missing-object reads, unexpected candidate growth, retained-byte age and lease counts. A reference-count implementation must update counts atomically with edges and reconcile drift; zero from an eventually updated counter is unsafe.
After discovering accidental deletion, halt the responsible workflow, identify exact generations and restore from available retained copies. Recreating metadata alone cannot repair missing bytes. Maintain deletion manifests with object identity, decision epoch and validation evidence for this investigation.
8. Failure tests and self-review
Test restore racing sweep, stale upload publication, lease expiry during a read, lost delete responses, object-key reuse, missed snapshot roots and a collector restart. Verify that every live root resolves to the intended generation and that repeated deletion cannot affect a replacement.
Follow-ups: Why is a grace period insufficient by itself? What must a backup retain? Can a URL promise outlive a reader lease? How would cross-tenant deduplication change the transaction boundary?
Score 0–2 each for complete roots, serialized lifecycle transitions, immutable generation handling, read/restore protection and realistic reclamation capacity.
Distinguish discovery throughput from deletion throughput
Additional original practice exercise · October 3, 2026. Numbers are illustrative assumptions.
Suppose ten million objects become unreachable per day. Average arrival rate is about 115.7 objects/s. A collector capped at 100 successful deletions/s cannot keep up even before retries: it removes at most 8.64 million/day, adding 1.36 million objects to backlog daily. At 50 KB/object, that is another 68 GB/day in decimal units.
A 1,000 deletions/s service facing the same continuing arrival rate drains an existing five-million-object backlog at a net rate near 884.3/s: roughly 5,654 seconds, or 94.2 minutes, under steady ideal conditions. This is longer than the 83.3-minute calculation that excludes new arrivals.
Practice: capacity is sufficient but oldest-candidate age rises. Check retained roots, failed metadata validation, tenant starvation and retries before raising deletion limits. Throughput cannot authorize deletion of a generation whose liveness is uncertain.
Related practice: Store durable objects with erasure coding · Design a tamper-evident audit log
Sources and next steps
- Apache Iceberg: maintenance — snapshot expiration and hazards of deleting apparent orphans while writes are in progress.
The object-registry protocol, restore race and capacity examples are original. They are not a description of Iceberg's internal implementation.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.