Video in progress
How do you choose between RDB and AOF persistence?
RDB / AOF — What is stored: the full state at a point in time / the sequence of write commands; Data loss: back to the last snapshot (minutes) / about 1 s with everysec, nearly none with always; File size: small, compressed / large, rewritten periodically; Restart time: fast / slower; Backup: easy: copy one file /…
📖 Answer
| RDB | AOF | |
|---|---|---|
| What is stored | the full state at a point in time | the sequence of write commands |
| Data loss | back to the last snapshot (minutes) | about 1 s with everysec, nearly none with always |
| File size | small, compressed | large, rewritten periodically |
| Restart time | fast | slower |
| Backup | easy: copy one file | more complicated |
Both use fork(): a child process writes to disk while the parent keeps serving. On a large instance (say 30 GB), the fork adds a few hundred milliseconds of latency, and thanks to copy-on-write, RAM can grow up to double if there are many writes. That's why you leave spare RAM on the server for Redis.
My usual choice:
- a pure cache: persistence off, or only an occasional RDB;
- sessions, queues, rate limit state: AOF
everysec, plus RDB for backups; - data you can't afford to lose: not in Redis at all, but in the DB.
Since Redis 7, the AOF consists of several files (base + incremental), the "multi-part AOF", so backup scripts need to be adapted to that.
Sign up to mark studied questions and save your progress.