Architect the Write Path and Crash Recovery for a Cloud-Native Database
System DesignModel answerLast updated
Design a distributed database that separates compute from storage, detailing how writes are committed durably, how a failed node recovers, and how quorum keeps the write path moving under slow or failed storage nodes.
The Problem
You are designing a cloud-native relational database. The architecture splits responsibility cleanly: a compute layer handles query parsing, transaction management, and buffer caching, while a storage layer is a fleet of independent nodes that persist data durably. The two layers scale independently, and compute nodes are treated as essentially stateless with respect to the on-disk data.
Your job is to walk through four connected design areas.
What to address
1. Write path
Describe every step that happens between a client sending an INSERT or UPDATE and the database returning a commit acknowledgment. Be specific about what data moves, in what order, and what has to land on disk before the client hears back.
2. Durability under compute failure Suppose the compute node crashes immediately after acknowledging a commit, before it has written any updated data pages to storage. What guarantees that the committed data is not lost? Explain the mechanism, not just the claim.
3. Crash recovery A replacement compute node comes online after the failure. Walk through how it reconstructs a consistent, usable view of the database. Pay particular attention to how it handles log records that were partially replicated at the time of the crash — records that may or may not represent committed transactions.
4. Storage-layer quorum Define the replication and quorum scheme for the storage nodes. Then explain specifically how you prevent a single slow storage node from stalling every write, and how you handle a network partition that makes some storage nodes unreachable.
Constraints and assumptions
- The storage fleet is spread across three availability zones (AZs). Your design must survive the complete loss of one AZ plus one additional node without losing any acknowledged data.
- Compute nodes do not own the data pages; they own the transaction log on the write path.
- You must explain how write amplification is kept low compared to a traditional replicated database.
- Latency targets to keep in mind: commit p99 under 10 ms, failover RTO under 30 seconds, RPO of zero for any acknowledged commit.
What a complete answer looks like
- A component-level description of the architecture (a diagram in text/ASCII is fine)
- The step-by-step write protocol, identifying exactly when and why the commit ACK is sent
- How the replacement compute node determines the safe recovery point (i.e., how it reconciles log sequence numbers across storage nodes)
- The quorum parameters you choose (read set, write set, total replicas), with justification, and your strategy for handling tail latency from slow disks
Hints
Hint 1
Think about what the single source of truth is: if the log is the database, what does that mean for where durability actually lives, and what does the compute node's buffer cache become?
Hint 2
For recovery, the key challenge is the log tail: some records at the very end of the log reached some replicas but not others. How do you figure out which records to keep and which to discard, and how do you prevent a zombie writer from racing with the new one?
Hint 3
For quorum, work backwards from the failure requirement. You need to survive AZ loss (removes 2 replicas) plus one more. Sketch out what V, W, and R need to be, and then think about what happens to write latency when you wait for W out of V responses instead of all V.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Core Principle: The Log Is the Database
The single idea that drives every other answer here is this: the compute node never writes data pages across the network. It writes only redo log records. Storage nodes durably persist those records and reconstruct pages from them in the background. Data pages in the compute node's buffer cache are a derived, disposable view — not the source of truth. Once you accept this, durability, recovery, and quorum design all follow naturally.
Architecture Overview
Client
│
▼
Writer (compute node)
SQL engine · transaction manager · buffer cache · LSN allocator
│
│ redo log records only (grouped by protection group)
▼
Storage fleet: 6 replicas per segment, 2 per AZ × 3 AZs
each node: inbound queue → durable SSD log → ACK
background: coalesce redo into page versions, gossip with peers, archive to object store
▲
Read replicas
consume the redo stream, read pages from the shared storage volume
Control plane: epoch management, health checks, membership, failover
The volume is divided into fixed-size segments (around 10 GB each). Each segment has its own protection group (PG) of 6 storage replicas. This matters for quorum and re-replication speed.
1. Write Path
- The client sends an
UPDATE. The writer executes it against pages in its buffer cache, fetching any misses from storage at the current read point. - The engine generates redo log records — compact descriptions of the change, not full pages. Each record gets a monotonically increasing Log Sequence Number (LSN) from a single allocator on the writer.
- Records are batched by protection group and sent concurrently to all 6 replicas in that PG. The writer does not wait for a majority before sending; it sends to all and waits for enough to respond.
- Each storage node appends the batch to its durable on-disk log and sends an ACK. This single sequential write to an SSD log is the only synchronous I/O on the foreground path.
- A log record is considered durable once 4 of 6 replicas ACK (the write quorum, explained below).
- The writer maintains the Volume Complete LSN (VCL): the highest LSN such that every record at or below it has reached write quorum, with no gaps.
- Transactions end with a Consistency Point LSN (CPL) record marking a complete mini-transaction boundary. The Volume Durable LSN (VDL) is the highest CPL at or below VCL.
- A transaction commits — and the ACK goes to the client — when its commit LSN ≤ VDL. A background group-commit thread advances VDL and notifies waiting transactions in batches, so no worker thread blocks on network I/O.
Why write amplification is low. A traditional replicated engine ships the redo log, the binlog, dirty data pages, and a double-write buffer, all multiplied across replicas. Here, six copies of a ~200-byte log record are transmitted instead of six copies of a 16 KB page. Page materialization is off the critical path entirely — storage nodes do it lazily, in parallel, in the background.
2. Durability Under Compute Failure
If the writer crashes immediately after sending a commit ACK, no data is lost. The reason: the ACK was only sent after the commit LSN reached VDL, which requires 4 of 6 durable log copies to exist on independent storage nodes. There is nothing else to flush. Data pages in the compute buffer cache are a cache of the log, not the authoritative copy. Losing the cache is harmless.
This also eliminates the classic checkpoint problem. There is no "dirty page flush," no double-write buffer, no need to ensure pages are consistent on disk before the log record is considered safe.
Uncommitted records — in-flight writes that never reached VDL — may exist on some storage nodes. Recovery handles them explicitly.
3. Crash Recovery and LSN Reconciliation
Step 1 — Fence the dead writer. The control plane increments the volume epoch and writes the new epoch to a quorum of every PG. Any storage node that receives a request carrying a stale epoch rejects it. This prevents a zombie writer (perhaps just paused, not actually dead) from corrupting the volume after recovery begins.
Step 2 — Reconstruct the log tail. The new writer contacts a read quorum (3 of 6) of each PG and collects each node's Segment Complete LSN (SCL): the highest LSN below which that node holds every record with no gaps. Because any 3-node read set intersects any 4-node write set, the union of what the new writer sees is guaranteed to include every record that ever reached write quorum.
Step 3 — Compute VCL and VDL. VCL is the highest gap-free LSN across all PGs. VDL is the highest CPL at or below VCL.
Step 4 — Truncate the tail.
The writer sends TruncateAbove(VDL, newEpoch) to all replicas. Records above VDL belong to transactions that were never acknowledged, so discarding them is safe by definition. The operation is epoch-stamped, making it idempotent if recovery restarts partway through.
Step 5 — Open for traffic. There is no redo replay at the compute layer. Storage nodes have been continuously materializing pages from the log in the background. The database is ready in seconds. Undo work for any uncommitted transactions that fall below VDL runs in the background after the database opens — it does not block availability.
New LSNs begin above VDL. Read-after-write is preserved because the new writer's read point starts at VDL, which includes every acknowledged commit.
A common mistake here is conflating "redo replay" with "recovery." Because compute is stateless and storage is log-structured, there is no replay step on the compute side. The confusion usually comes from applying a traditional ARIES-style recovery model to an architecture where the storage layer has already been applying redo all along.
4. Quorum Design and the Slow-Disk Problem
Parameters: V = 6, W = 4, R = 3
The two quorum invariants are:
- W + R > V (reads see the latest write)
- 2W > V (no two write sets can conflict)
Justification from the failure requirement:
- Losing a full AZ removes 2 replicas (2 per AZ × 3 AZs), leaving 4. Write quorum of 4 is still reachable.
- Losing an AZ plus one more node leaves 3. That is a read quorum, so the PG can be repaired without data loss.
- A simpler 3-replica design (2/3 quorum) cannot survive AZ+1 failure without data loss.
Tail latency / slow disk: Waiting for 4 of 6 ACKs means the 2 slowest nodes are simply ignored on the commit path. Empirically this cuts p99 latency significantly compared to waiting for all 6. Small segments (10 GB) re-replicate in roughly 10 seconds on a 10 Gbps link, which keeps the window for a double fault short and lets the system be aggressive about declaring a slow node unhealthy. Gossip between storage nodes fills in missed records in the background, never on the commit path. Reads do not require a quorum at all — the writer knows each node's SCL and routes each read to a single replica that is complete up to the needed LSN, preferring the lowest-latency one.
Membership changes: To replace a degraded node F with G without stalling writes, the PG transitions through an overlapping quorum rule: "4 of {A,B,C,D,E,F} AND 4 of {A,B,C,D,E,G}." This is reversible and does not require a write pause.
Partitions: If fewer than 4 replicas of a PG are reachable, writes to pages in that PG stall rather than proceed with a smaller quorum. This is the correct trade-off — the system chooses CP (consistency and partition tolerance) over availability for that segment. Reads can still proceed against the available replicas up to the last known VDL.
Trade-offs to Call Out
| Choice | Benefit | Cost |
|---|---|---|
| Log-only writes | Low write amplification, fast commit | Page reads may require applying accumulated redo; storage nodes need background CPU |
| 4/6 write quorum | Survives AZ+1, tolerates slow disks | More replicas than a 3-way scheme; higher storage cost |
| Stateless compute | Instant failover, no replay | Compute node has no persistent identity; session state must live in the client or a separate layer |
| Stall on partition | No data loss, no split-brain | A PG becomes unavailable if not enough replicas are reachable |