Build a Write-Ahead Log With Crash Recovery for an Order Store

Last updated: November 29, 2026

Quick Overview

Implement a small key-value store for order states that survives process crashes: every transaction is written to an append-only log with checksums and a commit marker before it becomes visible, and startup replays only fully committed transactions.

Amazon
Software Engineering Fundamentals
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

0

0 solved


Implement a small key-value store for order states that survives process crashes: every transaction is written to an append-only log with checksums and a commit marker before it becomes visible, and startup replays only fully committed transactions.

Storage teams behind services like DynamoDB and Aurora care deeply about durability semantics, and the write-ahead log is the core idea. The interviewer checks ordering of log write, fsync, and apply, detection of torn writes, and atomicity of multi-key transactions on recovery.

What the Interviewer Expects
  • Writes the log and fsyncs before acknowledging or applying
  • Frames records with length and checksum to detect torn writes
  • Uses commit records so partial transactions are discarded
  • Truncates the corrupt tail after recovery so new appends are clean
  • Discusses checkpointing to bound recovery time
Key Topics to Cover
write-ahead log
durability
crash recovery
checksums
atomic commit
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 or snapshots so the log does not grow forever?
  • How does group commit improve throughput?
  • What does fsync actually guarantee, and what about the directory entry?
  • How would you replicate this log to a second machine?
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({key: value}) is atomic and durable once it returns; None deletes.
  • A crash at any byte boundary must recover to the state after some prefix of committed transactions.
  • Recovery must no...
High-Level Design

Each record is length | crc32 | json. A transaction appends its puts, then a commit record, flushes, and calls fsync; only then does it update the in-memory map. Recovery reads records until the f...


Submit Your Answer
Markdown supported