← Questions

Database internals: WAL, MVCC, replication and recovery

0
AmazonCodingLast asked Jan 2026

A coding interview question asked in Amazon's technical phone screen, last asked Jan 2026. It tests databases, concurrency control and storage engines.

Explain how a relational database keeps data durable, consistent and available when it runs on a cloud storage layer shared by several replicas. Walk through four mechanisms in turn, then put them together: what happens, step by step, between a client's COMMIT and the moment that data is safe on disk and visible on a replica.

Part 1: write-ahead logging

  • What goes into a log record, and why the log is written before the data pages.
  • Why a commit is durable once its log records are flushed, even though the changed pages are still only in memory.
  • Group commit, checkpoints, and what a checkpoint lets the database throw away.

Part 2: multi-version concurrency control

  • How several versions of a row are kept, and how a transaction's snapshot decides which version it sees.
  • Why readers never block writers and writers never block readers.
  • Which anomalies each isolation level allows (dirty read, non-repeatable read, phantom, write skew), and how old versions are cleaned up.

Part 3: replication

  • Physical (log) shipping against logical replication; synchronous against asynchronous.
  • What a replica's lag means for a reader, and how a quorum of storage copies (for example 4 of 6 for writes, 3 of 6 for reads) survives losing a node or a whole zone.
  • What changes when the storage layer applies the log itself, so the database ships only log records instead of full pages.

Part 4: crash recovery

  • The redo and undo phases, and how log sequence numbers tell recovery where to start.
  • Why recovery time depends on the checkpoint interval, and how a storage layer that replays the log continuously makes restart fast.

Clarifying questions

  • Single primary with read replicas, or several writers?
  • Which isolation level does the application use by default?
  • How much data loss (RPO) and downtime (RTO) is acceptable when a zone fails?

What a strong answer covers

  • The ordering rule of write-ahead logging, stated precisely: no data page reaches disk before the log records that describe it.
  • Snapshot visibility explained with transaction ids or commit timestamps, plus the cost of a long-running transaction holding back cleanup.
  • A clear trade-off between commit latency and durability for each replication choice.
  • Recovery reasoned about with log sequence numbers, not hand-waving about "replaying the log".
  • Where consistency, latency and throughput pull against each other, and which one each mechanism gives up.

Follow-ups

  • A replica serves a read that misses a row the client just wrote. Why, and how do you give that client read-your-writes?
  • The primary fails mid-transaction. Which of its transactions survive on the new primary?
  • As write load grows, what runs out first: the log, lock contention, or replication?

Where it's asked

  • Amazon · Technical phone screen · Last asked Jan 202660 min · Live coding in a shared editor that does not run code, plus Leadership Principles questions · No AI

What it tests

databases · concurrency control · storage engines

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding