The interview problem
A distributed file service must move a directory to a new parent while clients are creating children and reading paths. Design atomic namespace semantics without copying every file.
Original practice, not a reported company interview. All worked numbers are illustrative. Interview date: not applicable. Written October 3, 2026.
1. Scope and assumptions
Use stable inode-like IDs and parent/name directory entries. Distinguish namespace atomicity from durability and from moving file contents across storage systems. Reject moving a directory beneath itself.
2. Architecture and decisions
Resolve source and destination → lock or transact metadata → validate ancestry → atomically switch entries → commit
Make rename a metadata transaction that removes the source entry and inserts the destination entry with the same object ID. Serialize against conflicting creates and renames in both parent directories. Validate cycle constraints against a consistent view; checking ancestry before acquiring the relevant serialization protection leaves a race. Define replacement behavior for existing destinations explicitly.
Readers should resolve a path under a consistent namespace view or detect version changes and retry. Open file handles can continue to reference stable IDs even after paths change. When parents live on different metadata shards, use a supported cross-shard transaction or restrict the operation; independent delete and insert cannot provide atomic visibility.
3. Work through the example
If a directory contains one million files, a stable-ID metadata rename can update two directory entries rather than copy one million file bodies. That is a logical operation count, not a constant latency guarantee: ancestry checks, indexes, locks and cross-shard coordination still cost work.
4. Failure cases and trade-offs
A crash between separate delete and insert loses the path or creates duplicate names. Two concurrent moves can create a cycle if ancestry checks are not serialized. Co-locating related metadata simplifies transactions but can create hot shards. Cross-shard atomicity increases coordination latency and failure-handling complexity.
5. Validation and acceptance
Run concurrent child creation, destination replacement and opposing directory moves. Crash at transaction boundaries and assert readers see a valid old or new namespace state. Test open handles independently from path resolution and verify durability after recovery.
6. Follow-ups and self-review
What semantics should a recursive listing have during rename? Reward stable identity, atomic entry changes, cycle prevention and explicit cross-shard constraints.
Sources and related practice
Linux rename documentation describes local namespace semantics and cross-filesystem limits; the distributed metadata design is original.
Read the primary technical reference
Reference retrieved October 3, 2026. Retrieval date is not an interview or source publication date. The reference supports the named concept; scenario, architecture, examples and rubric are original.
Continue with Publish generated files with atomic name replacement; Recover from missed filesystem watch events.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.