KatInterview

Architect the Write Path and Crash Recovery for a Cloud-Native Database

System DesignModel answer
HardModel answerSystem Designdistributed-systemsdurabilityreplication

Last 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.