The interview problem
A service regenerates a configuration file while readers open it continuously. Prevent readers from seeing half-written content and specify crash durability separately.
Original practice, not a reported company interview. Scenarios and numbers are illustrative. Interview date: not applicable. Sources retrieved October 1, 2026.
1. Scope and worked approach
Assume a local filesystem with documented same-filesystem rename semantics. Write a temporary file in the destination directory, validate its contents, flush as required, then rename it over the destination. Readers opening the path obtain an old or new complete file under the chosen platform contract; existing descriptors may continue reading the old object. Sync the containing directory where required for crash persistence. Do not claim that arbitrary cross-filesystem moves are atomic.
2. Trace the design or derivation
Write local temporary file → validate → persist content → replace name → persist directory
Keep the temporary filename unguessable and ensure ownership, permissions and format are finalized before replacement. Readers that memory-map or retain open descriptors need a refresh policy; atomic path replacement will not force them to reopen. Cleanup must distinguish abandoned temporaries from a file still being prepared by another publisher.
3. Calculate the example
A 4 MB file written at 20 MB/s takes about 0.2 seconds of payload writing. Writing directly to the destination exposes that interval to readers. Temporary writing plus one name switch avoids partial publication, but does not make the 0.2 seconds disappear or guarantee the rename survives sudden power loss without the required persistence operations.
4. Failure cases and trade-offs
A permission mismatch on the temporary file can lock out readers after publication. Two publishers need version checks or coordination to prevent stale output replacing newer output. Atomic visibility and durable survival are different properties; copying across volumes changes the protocol.
5. Validation, follow-ups and self-review
Continuously read checksummed versions while killing the writer at each stage. Check permissions, open descriptors and reboot behavior on the actual filesystem. Follow-up: how are abandoned temporary files cleaned? Reward complete-file visibility, concurrency control and a separate durability claim.
Sources and related practice
Technical reference: docs.python.org — Same-filesystem replacement semantics; crash durability needs a separate filesystem contract.
Source publication/update: Not established. Retrieved October 1, 2026. The workflow, calculations and review exercises are original; this reference is not evidence that a company asked this question.
Continue with Roll out server configuration safely; Batch durable commits without acknowledging volatile data.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.