Reference · Cheat sheet

Persistence: RDB vs AOF

Snapshot vs log — and the fork trick. Print it, pin it.

From lesson 0005See also glossary

Side by side

RDB (snapshot)AOF (log)
WhatBinary point-in-time dumpAppend log of every write, replayed on start
Triggersave N M, BGSAVEcontinuous; BGREWRITEAOF to compact
DurabilityLose minutes since last snapshotLose ≤ ~1s (everysec)
FileCompact — ideal backup/DRBigger; needs rewrite
RestartFaster on big datasetsSlower (replay)

appendfsync (AOF durability dial)

PolicyfsyncWorst-case loss
alwaysevery write≈ none (slowest)
everysec (default)1×/second~1s (bounded ~2s)
noOS decides~30s

fork() + copy-on-write

Latency gotcha

fork() on a big instance can stall the single command thread for milliseconds–seconds (head-of-line blocking). Bigger dataset + more write churn = bigger spike.

Which to use

Both for PostgreSQL-comparable safety: RDB = cheap backups + fast restart, AOF = tight (~1s) loss window. RDB-only if a few minutes of loss is acceptable. AOF-only is discouraged (keep occasional RDB for backups/restarts).

← lesson 0005 · Sources: Redis Docs — Persistence · antirez — persistence demystified