Back to System Design Lab

The database disk was wiped mid-sale. Not one order went with it.

The same load as the payment test runs again. At second 50 Postgres is killed and its data disk deleted. Pick a backup method and see how long the shop takes to recover and how many orders are saved.

Backup method

Recovery, seconds13.8
Data lost, seconds21.4
Paid lost2,439
Lost in the end0

Archive every 30 seconds

The last WAL archive left 21.4 seconds before the disk was lost. Backup plus archive brings the books back only to that point. 2,439 paid orders are missing. The shop then refills the books from its record in Redis in 1.9 seconds, and the gap drops to zero.

From the crash to complete books

  1. Disk deleted2.3 seconds
  2. Copy backup5.0 seconds
  3. Replay WAL archive6.5 seconds
  4. Refill from Redis1.9 seconds

Paid orders recorded in the books

  • After restore, against the books when the disk was lost1,580 of 4,019
  • After the Redis replay, against the shop’s record at the end5,957 of 5,957
Show the technical side
Archive every 30 secondsPostgres default settingspgBackRest, archive every 30 seconds
archive_timeout30 s0 s30 s
Full backup before the sale1.7 s, 7.8 MB1.6 s, 7.8 MB5.2 s, 7.8 MB
RTO: crash to accepting writes13.8 s10.2 s10.9 s
WAL lost with the disk21.4 s52.2 s21.1 s
Lost with backup alone2,784 orders, 2,439 paid6,187 orders, 5,168 paid3,357 orders, 3,320 paid
Redis stream replay1.9 s2.0 s1.7 s
Lost after replay000
Ledger afterwardsbalanced, revenue matchesbalanced, revenue matchesbalanced, revenue matches
  • The shop keeps selling while Postgres is down. Stock and orders live in Redis, and the worker retries writes with backoff until Postgres is back.
  • What the worker cannot save on its own are messages acknowledged before the crash that only partly reached the archive. Those come back through worker -isi-ulang, which replays the stream.
  • The zero-loss result depends on Redis: the stream is not trimmed, and Redis writes its AOF every second to another disk. If Redis and Postgres are lost together, only the backup and archive remain.
  • pgBackRest 2.60.0 takes about three times longer to back up (manifest, per-file checksums, zstd compression), but adds verify, retention, and incremental backups.
  • An RPO near zero without Redis needs a replicated standby. That belongs to the resilience experiment.