Video in progress
How do you choose a persistence strategy for Redis: RDB, AOF, both, or turning it off entirely? Explain it in terms of RPO and RTO.
First I get the RPO (how much data we can afford to lose) and RTO (how fast we must recover) numbers from the business. For a pure cache, persistence is often unnecessary, or just RDB for a fast warm-up; for a Redis that holds state, AOF everysec + RDB and a replica.
📖 Answer
Persistence isn't free: fork(), disk I/O, CoW memory, startup time. So turning it on "just in case" isn't right.
| Approach | RPO | Restart | Cost |
|---|---|---|---|
| No persistence | everything | instant, but empty | cheapest |
| RDB only (every 15 minutes) | up to 15 minutes | fast (binary load) | periodic fork |
AOF everysec |
about 1 s | slower, if the AOF is long | constant disk writes + rewrite |
| AOF + RDB preamble | about 1 s | fast | the cost of both |
| Persistence only on the replica | about the replication lag | through failover | a lighter master |
I decide by data type:
A pure cache: RPO doesn't matter, since the source is in the DB. But RTO can matter: warming a 200 GB cache from cold will take the DB down. In that case RDB is useful only for a "hot start": loading takes a few minutes, but there's no shock to the DB. For a small cache, I turn persistence off and rely on cold start protection.
Sessions, rate limit state: losing a few minutes means everyone logs in again. A replica + RDB is enough.
Queues, idempotency, state: AOF everysec, replicas, min-replicas-to-write. Even then the RPO isn't zero, and the business must accept that in writing.
Operational aspects:
- turning persistence off on the master and enabling it only on the replica removes the fork latency on the master. But if the master dies and automatically restarts empty with no persistence, the replicas connect to it and wipe their own data too. This is a classic trap, so in such a setup the master must be protected from automatic restart;
- backup = copying the RDB file elsewhere (S3) and regularly restoring it in a different environment. A backup that hasn't been restored isn't a backup;
- disk speed and size: during an AOF rewrite you may need double the space.
On managed services this choice turns into the "snapshot schedule" and "Multi-AZ" settings, but the question is the same: what are the RPO and RTO.
Sign up to mark studied questions and save your progress.