Crash Recovery Replay for a Checksummed Transaction Log

Last updated: November 29, 2026

Quick Overview

Implement recovery for a write-ahead log of PUT and COMMIT records, each carrying an LSN, length and CRC32: replay only committed transactions after a checkpoint, stop cleanly at a torn or corrupt tail or a non-consecutive LSN, and return the recovered state plus the offset where new appends should begin.

Pure Storage
Coding & Algorithms
Software Engineer
Pure Storage
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Implement recovery for a write-ahead log of PUT and COMMIT records, each carrying an LSN, length and CRC32: replay only committed transactions after a checkpoint, stop cleanly at a torn or corrupt tail or a non-consecutive LSN, and return the recovered state plus the offset where new appends should begin.

Purity protects acknowledged writes in NVRAM and metadata in logs, so power loss mid-write and torn records are everyday design inputs on the core team. This question tests binary parsing, precise crash semantics (what counts as durable), and the reasoning to defend each stopping rule.

What the Interviewer Expects
  • Parses fixed headers with struct and validates length before reading the body
  • Verifies the checksum over header fields and payload, not payload alone
  • Stops at the first invalid record and explains why it never skips past it
  • Applies a transaction only when its COMMIT is seen, discarding uncommitted staged writes
  • Skips records already covered by the checkpoint
  • Returns a truncation offset so stale bytes after the tail are not reinterpreted later
Key Topics to Cover
Write-ahead logging
Crash consistency
Checksums
Binary parsing
Recovery
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How do you handle a transaction that started before the checkpoint and committed after it?
  • How would you detect stale but valid-looking records from an earlier lap of a circular log?
  • How would you make recovery parallel for a multi-GB log?
  • What if the checksum itself can collide with garbage, and how would you reduce that risk?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Record layout: crc32 (4 bytes), lsn (8), payload length (4), kind (1), payload. The CRC covers everything after the CRC field. PUT payload: txid (8), key length (2), key, value. COMMIT payload: txid. ...

High-Level Design

Scan forward. For each record: check that the full record fits, verify the CRC, and check that the LSN is exactly one more than the previous record. Any failure means the log ends here, because record...


Submit Your Answer
Markdown supported

Related Questions