Thread-Safe Coalescing Write Buffer With Sync Barriers
Last updated: November 29, 2026
Quick Overview
Implement a bounded in-memory write buffer keyed by logical block address where many writer threads add writes (blocking when full, with newer writes to the same LBA replacing older ones), a single flusher drains batches to the backend, and sync(seq) blocks until all writes up to a sequence number are durable.
Pure Storage
November 29, 20260
0
0 solved
Implement a bounded in-memory write buffer keyed by logical block address where many writer threads add writes (blocking when full, with newer writes to the same LBA replacing older ones), a single flusher drains batches to the backend, and sync(seq) blocks until all writes up to a sequence number are durable.
FlashArray acknowledges writes once they are safe in NVRAM and later flushes them to flash in large batches, so the producer and consumer problem with durability barriers is central to Purity's data path. Interviewers check condition variable discipline, doing slow I/O outside the lock and getting the durability semantics exactly right.
What the Interviewer Expects
- Uses one lock with separate conditions for not-full, has-data and flush-done
- Always waits in a while loop to handle spurious wakeups
- Performs backend I/O without holding the lock
- Coalesces overwrites to the same LBA without breaking the sync guarantee
- Supports clean shutdown that drains pending writes
- Explains why an overwrite of a buffered LBA should not block when full
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 support multiple flusher threads without reordering writes to the same LBA?
- What happens to sync guarantees if the backend write fails halfway through a batch?
- How would you replace the global lock to scale to dozens of cores?
- How does this map onto a real NVRAM-backed design where the buffer itself is durable?
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
write(lba, data) returns a monotonically increasing sequence number and blocks only if the buffer holds capacity distinct LBAs and this LBA is not already buffered. sync(seq) returns once every ...
High-Level Design
State is guarded by one mutex: pending (dict LBA to data), write_seq, flushed_seq. Three condition variables share the mutex. The flusher swaps out the whole dict and records seq = write_seq u...