Make a Key Value Store Crash Safe With a Write-Ahead Log
Last updated: November 29, 2026
Quick Overview
Add durability to a key value store: each atomic multi-key commit must survive a process crash or power loss once commit returns, and recovery must ignore partially written records. Implement the log format, commit path, and recovery.
Microsoft
November 29, 20260
0
0 solved
Add durability to a key value store: each atomic multi-key commit must survive a process crash or power loss once commit returns, and recovery must ignore partially written records. Implement the log format, commit path, and recovery.
Storage and database teams at Microsoft (SQL Server, Azure Cosmos DB, Azure Storage) build on write-ahead logging, and this question tests whether the candidate understands durability rather than just using a database. Interviewers check write ordering, fsync, checksums for torn writes, commit records for atomicity, and recovery logic.
What the Interviewer Expects
- Writes and fsyncs the log before applying changes in memory
- Uses a commit record so multi-key transactions are all or nothing
- Detects torn or corrupt tail records with checksums
- Recovers by replaying only committed transactions
- Explains checkpointing to bound log size and recovery time
- Discusses group commit for throughput
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you add checkpoints so the log does not grow forever?
- How does group commit improve throughput, and what does it cost in latency?
- What does fsync on the file not guarantee, and when do you also fsync the directory?
- How is this different from undo logging?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
commit({k: v, ...})applies several writes atomically (a value ofNonedeletes).- Once
commitreturns, the writes survive a crash. - After a crash at any point, restart recovers exactly the t...
High-Level Design
Write-ahead rule: the log record describing a change must be durable before the change is considered committed. Each transaction appends one record per key and then a commit record, all in one...