Skip to content

Lesson 1 of 9 · 22m

Persistence: RDB, AOF, and What Restart Really Means

Redis is memory-first, not magically durable. Learn exactly what RDB snapshots and AOF files guarantee before you trust them with data you cannot lose.

The first Redis production surprise is usually simple: Redis is an in-memory database that can persist, not a persistent database that happens to be fast. If the process dies, memory is gone. What returns after restart depends entirely on how you configured persistence — and what you were willing to pay in latency and disk I/O.

RDB is a point-in-time photograph

RDB snapshots serialize the dataset to dump.rdb at configured intervals:

save 900 1
save 300 10
save 60 10000
dir /var/lib/redis
dbfilename dump.rdb

That configuration means: snapshot after 15 minutes if one key changed, after five minutes if ten changed, or after one minute if ten thousand changed. The guarantee is therefore bounded loss. A crash 30 seconds before the next snapshot loses every write since the previous one.

Snapshots are compact and fast to load, which makes them good for backups, cold restarts, and disaster recovery copies. They are not a write-ahead log.

AOF is the write journal

The append-only file records write commands in replayable form:

appendonly yes
appendfsync everysec
appendfilename appendonly.aof
dir /var/lib/redis

appendfsync is the real durability dial:

  • always — fsync every write; strongest guarantee, highest latency cost.
  • everysec — usually lose at most one second; the normal production compromise.
  • no — let the kernel decide; fast, but a machine crash can lose tens of seconds.

Modern Redis stores AOF as a manifest plus incremental/base files. BGREWRITEAOF compacts it by writing the smallest command sequence that reconstructs the current dataset.

You can combine them, and usually should

A common arrangement is AOF for restart durability plus periodic RDB copies off-host for backup. Redis loads AOF preferentially when it exists because it represents the newest history.

Test the actual path, not the theory:

redis-cli DEBUG RELOAD
redis-check-aof /var/lib/redis/appendonlydir/manifest
redis-check-rdb /var/lib/redis/dump.rdb

The operational truth

Persistence protects against process restarts and some host failures. It does not protect against accidental deletion, corrupted disks, bad failovers, or someone running FLUSHALL. Backups, replication, and restore drills are separate controls.

A Redis node with save "" and appendonly no is a cache. Nothing wrong with that — as long as everyone using it knows it.

Field notes

  • appendfsync everysec can still lose the last second; "durable" is a probability and timing statement, not a magic word.
  • Fork-based persistence gets expensive on large-memory instances because copy-on-write duplicates dirty pages during heavy writes.
  • Never run persistence checks only on a quiet staging instance; disk latency shows up when rewrite and write load overlap.
  • AOF rewrite failures are emergencies: the old file keeps growing and disk exhaustion becomes a second outage.

Was this lesson helpful?

Sign in to rate