Log-Structured Storage: Replication, Recovery, and MVCC
System DesignModel answerLast updated
Describe how log-structured databases decouple compute from storage, use quorum-based replication, achieve fast recovery, and handle multi-version concurrency control.
Modern distributed databases separate the compute tier from the storage tier by shipping only log records to storage nodes, rather than flushing complete data pages. This architecture reduces write amplification and enables highly available, low-latency operations.
Your task is to explain how this log-centric architecture works, covering four key areas:
Part 1: Log-Centric Storage Model
Describe how a log-based storage system differs from traditional page-oriented databases. What does the compute node send to storage, and what work is moved out of the critical write path? How does the storage layer reconstruct pages when they're needed?
Part 2: Quorum-Based Replication
Consider a system that replicates each storage segment across 6 nodes (2 per availability zone, spanning 3 zones). Explain how quorum writes work in this setup. What are reasonable quorum sizes for reads and writes, and why? How does this design tolerate availability zone failures while maintaining write availability?
Part 3: Fast Recovery Mechanism
Compare the recovery process after a crash between traditional log-replay systems and log-structured storage. Why can the log-structured approach resume operations in seconds rather than minutes? What bookkeeping is required to identify a consistent recovery point?
Part 4: Multi-Version Concurrency Control
Explain how physical page versioning at the storage layer interacts with logical row-level MVCC at the compute layer. Does moving to log-structured storage eliminate the need for garbage collection or vacuum processes? Why or why not?
Throughout your answer, contrast this design with conventional architectures where the database engine writes full pages to disk during checkpoints.
Hints
Hint 1
Think about what happens to dirty pages in the buffer pool when the storage layer can reconstruct them from logs
Hint 2
Consider the tail latency benefits of waiting for only K out of N acknowledgments
Hint 3
Recovery speed depends on whether redo work was deferred or done continuously
Hint 4
Physical page versioning and logical transaction visibility are orthogonal concerns
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer: Log-Structured Storage Architecture
1. Log-Centric Storage Model
Traditional page-based systems couple the database engine tightly to storage. When a transaction commits, the engine must:
- Write and fsync the write-ahead log
- Eventually flush modified pages (8-16 KB each) from the buffer pool to disk
- Use mechanisms like doublewrite buffers or full-page writes to prevent torn pages
- Replicate both logs and pages to standby nodes
This creates massive write amplification: a small row update generates multiple large I/O operations across logs, pages, and replicas.
Log-structured storage fundamentally inverts this model. The compute node:
- Generates only redo log records (typically tens to hundreds of bytes)
- Sends these records to a distributed storage fleet
- Never writes data pages to storage
- Can evict dirty pages from its buffer pool at any time without durability concerns
The storage nodes handle all page-level work asynchronously:
- Persist incoming log records to local SSDs and acknowledge immediately
- Apply log records to materialize page versions in the background
- Gossip with peer replicas to fill gaps in the log sequence
- Archive completed page versions to object storage
- Perform garbage collection and integrity checks offline
When a page is requested at a specific log sequence number (LSN), storage locates the most recent materialized version below that LSN and applies any subsequent log records to bring it current.
Benefits: Write latency drops dramatically because only small sequential log appends block commits. Page I/O, which is random and large, moves entirely off the critical path. Measurements show 7-10x reduction in network traffic and similar reductions in write I/O.
2. Quorum-Based Replication
The system divides the storage volume into segments (e.g., 10 GB each). Each segment forms a protection group replicated across 6 nodes: 2 copies in each of 3 availability zones.
Quorum sizing: For a replication factor of V=6, appropriate quorum values are:
- Write quorum Vw = 4
- Read quorum Vr = 3
These satisfy two critical properties:
- Read-write overlap: Vw + Vr > V (4 + 3 > 6), ensuring every read quorum intersects the most recent write quorum
- Write-write exclusion: 2·Vw > V (8 > 6), preventing conflicting concurrent writes from both succeeding
Failure tolerance:
- Loss of one entire AZ (2 nodes): 4 nodes remain, writes continue uninterrupted
- Loss of one AZ plus one additional node: 3 nodes remain, reads still work and the system can rebuild missing replicas
- The small 10 GB segment size enables rapid repair (under 10 seconds on modern networks), minimizing the vulnerability window
Latency characteristics: A write commits when the 4th-fastest acknowledgment arrives out of 6. This masks tail latency beautifully—a slow or failed replica doesn't block progress. Unlike traditional 2-way mirroring where the slowest replica determines commit latency, quorum systems maintain low percentile latencies even with stragglers.
For reads, the system typically avoids quorum operations. The writer tracks which segments are current (have received all records up to a given LSN) and reads from any single up-to-date replica with good latency. Quorum reads occur only during recovery scenarios.
3. Fast Recovery Mechanism
Traditional recovery (ARIES-based): After a crash, the database must:
- Analyze the log to identify checkpoint state
- Redo: replay the log from the last checkpoint, re-reading pages from storage and reapplying changes serially on a single node
- Undo: roll back uncommitted transactions
This takes seconds to minutes because redo work was deferred until failure. The database remains unavailable throughout.
Log-structured recovery: Since storage nodes apply redo continuously across thousands of nodes in parallel, there's no deferred redo work. Recovery becomes a bookkeeping exercise:
The system maintains several LSN watermarks:
- SCL (Segment Complete LSN): highest LSN with no gaps in a particular segment
- VCL (Volume Complete LSN): highest LSN where all segments have received all prior records at write quorum
- CPL (Consistency Point LSN): end of the last complete mini-transaction (atomic multi-page operation like a B-tree split)
- VDL (Volume Durable LSN): highest CPL ≤ VCL, representing the last consistent state
On restart, the new compute node:
- Contacts a read quorum of each protection group
- Computes VDL by examining SCL values
- Issues a truncate operation for all records above VDL
- Marks the truncation with a new epoch to prevent stale writers from causing inconsistency
The database becomes available in under 10 seconds. Undo operations run in the background while serving user traffic, because they're logical operations (doesn't require the database to be offline).
The system also uses a flow control mechanism (LSN Allocation Limit) to prevent the compute node from getting too far ahead of VDL, bounding the maximum recovery work.
4. Multi-Version Concurrency Control
It's crucial to distinguish two independent versioning layers:
Physical page versioning (storage layer):
- Storage maintains multiple timestamped versions of each page, indexed by LSN
- Each read request specifies a read-point LSN (typically the current VDL)
- Storage serves page versions consistent with that LSN
- Garbage collection removes page versions below the minimum read-point LSN across all readers
- This eliminates checkpoint-driven page management and provides snapshot isolation at the physical layer
Logical transaction visibility (compute layer):
- The database engine still implements traditional MVCC using undo logs, transaction IDs, and visibility maps
- MySQL-based systems still maintain undo records and require purge operations
- PostgreSQL-based systems still track transaction IDs in tuple headers and require VACUUM
What changes: The I/O cost of MVCC maintenance drops dramatically. Undo pages and vacuum-modified pages are just more log records that storage handles asynchronously. The compute node never flushes them synchronously.
What doesn't change:
- Long-running transactions still block garbage collection
- Table bloat still occurs if cleanup can't keep up
- Transaction ID wraparound concerns remain in PostgreSQL-derived systems
A common misconception is that log-structured storage eliminates the need for vacuum or purge. It doesn't. It makes these operations cheaper from an I/O perspective, but they're still necessary to reclaim space and maintain system health. The physical versioning at storage and logical versioning at the compute layer solve different problems and both require cleanup.
Common Pitfalls
Strong candidates avoid these mistakes:
- Claiming vacuum is eliminated: Physical page versioning doesn't replace logical MVCC cleanup
- Forgetting flow control: The system must bound how far ahead the writer can get from durable state
- Confusing read and write quorums: Reads typically use one replica; quorum reads are exceptional
- Missing the continuous redo insight: Recovery is fast because work wasn't deferred, not because of faster algorithms
- Ignoring the small segment size: Fast repair is critical to the multi-failure tolerance argument
The architecture's elegance lies in moving expensive, bursty I/O (page flushes, checkpoints) off the critical path and distributing it across a storage fleet that processes it continuously in parallel.