Lesson 6 of 9 · 28m
RDB, AOF, and the Real Durability Tradeoffs
Understand snapshots, append-only files, fsync policy, rewrite behavior, and what Redis can and cannot promise after a crash.
Redis persistence is often summarized as "RDB is snapshots, AOF is every write." That sentence is technically true and operationally inadequate. The real questions are how much data you can lose, how quickly you can restart, how expensive persistence is under write load, and whether your recovery procedure has ever been tested.
RDB is a point-in-time snapshot
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
dbfilename dump.rdb
dir /var/lib/redisThose defaults mean: snapshot if at least one key changed in 900 seconds, ten in 300, or ten thousand in 60. RDB files are compact and fast to load, making them good for backup and restart. They are also inherently lossy between snapshots. If the server crashes five minutes after the last save, those five minutes are gone.
AOF records write operations
appendonly yes
appendfsync everysec
no-appendfsync-on-rewrite no
aof-use-rdb-preamble yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mbappendfsync always is the strongest common setting and the most expensive. everysec usually balances durability and throughput: a crash can lose roughly the last second of acknowledged writes, depending on exact timing and operating-system behavior. no leaves fsync timing largely to the kernel and increases possible loss.
Acknowledged does not mean immortal
A write acknowledgement means Redis processed the command. It does not necessarily mean the data reached durable disk at that instant, unless fsync policy and deployment details support that conclusion. Redis is not a substitute for a relational database when zero data loss and complex transactional integrity are mandatory. It can still be a valid system of record when the business accepts bounded loss or rebuilds state from authoritative events.
Rewrites reduce growth but add load
The AOF grows as writes accumulate. Rewriting compacts it, often using an RDB preamble plus incremental commands. During rewrite, Redis still handles traffic while persisting. This creates CPU, memory, and I/O pressure. Do not schedule or trigger rewrites casually at peak without measuring.
redis-cli info persistence | grep -E 'aof_|rdb_|loading'
redis-cli lastsave
redis-cli bgrewriteaofManual commands belong in controlled operations, not as a routine cron-driven ritual unless you understand the blast radius.
Backups are not restores
Copying dump.rdb or the AOF while Redis is running can produce a valid artifact only when you understand how the file is written. Prefer snapshots generated by Redis or filesystem-level consistency guarantees appropriate to your platform. Most importantly, restore in an isolated environment and verify keys, TTLs, versions, and startup behavior. A backup never restored is a hypothesis.
Field notes
stop-writes-on-bgsave-error yesprevents silent loss of durability when snapshots fail; disabling it without alerting is negligence.- Fork latency rises with memory size and host constraints. Measure
latest_fork_usec. - AOF corruption at startup is rare but real; know how
redis-check-aofworks before incident night. - Container deployments frequently lose data because
/var/lib/redisis ephemeral. Check the volume, not the Helm chart marketing.
Was this lesson helpful?