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
Software Engineering Fundamentals
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

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
write-ahead logging
durability
crash recovery
atomicity
checksums
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample Answer
Requirements
  • commit({k: v, ...}) applies several writes atomically (a value of None deletes).
  • Once commit returns, 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...


Submit Your Answer
Markdown supported