A team wants to use Redis as the system of record for data with monetary value. What durability posture would you configure, and what would you tell them they can still lose?
answer
- Ask for RPO and RTO per failure class before configuring
- everysec + off-host snapshots + replicas in separate domains
- Async replication: failover can discard acknowledged writes
- WAIT / WAITAOF (7.0) confirm after the fact, not synchronous commit
- min-replicas-to-write trades availability for less silent loss
basics
~20 sSet AOF on with everysec or always, snapshots shipped off-host, and replicas in separate failure domains. Then state the residual risk plainly: asynchronous replication means a failover can discard acknowledged writes, so money needs reconciliation against a durable source elsewhere.
solid answer
~50 sConfiguration: `appendonly yes` with `appendfsync everysec` (or `always` if the write rate and disk allow), hybrid base for fast loading, periodic `BGSAVE` snapshots copied off-host for point-in-time restore, replicas in a different failure domain, and host settings right (overcommit on, huge pages off, memory headroom for copy-on-write). Then the honest part. Even fully configured, they can lose: up to a second on power loss with `everysec`; **any** acknowledged write not yet replicated when a master fails over, because Redis replication is asynchronous; and everything if a bad write propagates instantly to replicas. `WAIT` and, since 7.0, `WAITAOF` let a specific write confirm replication or fsync at a latency cost, but they are post-hoc confirmation, not synchronous commit. So my recommendation is usually: Redis for the fast path, a durable store as the reconciliation authority for anything monetary, plus written RPO and RTO figures rather than a vague sense of safety.
code
text · 13 linesappendonly yes
appendfsync everysec # ~1s power-loss window; 'always' if the disk allows
aof-use-rdb-preamble yes # fast base load -> shorter RTO
save 900 1 # snapshots for restore, not for the loss window
min-replicas-to-write 1 # refuse writes we cannot replicate
min-replicas-max-lag 10
# Per-write confirmation, at a latency cost, for the writes that truly need it
> WAIT 1 100 # wait for 1 replica to ack, max 100 ms
(integer) 1
> WAITAOF 1 1 100 # local fsync + 1 replica fsync (Redis 7.0+)
1) (integer) 1
2) (integer) 1go deeper
Know that AOF plus replicas plus backups is the durable-leaning setup, and that Redis is normally a cache rather than a system of record.
Name the settings and give the loss window for each, and say that replication is asynchronous.
Design the full posture including failure domains, min-replicas-to-write, backup rehearsal and persistence-health alerting, and quantify the windows.
Lead with RPO and RTO per failure class, state the residual risk in writing, weigh availability against silent loss, and recommend a durable authority elsewhere for monetary data with Redis on the fast path.
## Start by refusing the vague version of the question "Make Redis durable" is not actionable. Two numbers make it so: - **RPO** (recovery point objective): how much recent data may be lost, per failure class. Process crash, power loss, node loss with failover and whole-region loss are four different numbers, and Redis behaves differently in each. - **RTO** (recovery time objective): how long the service may be down while recovering. This is where AOF size and load time enter, since restoring a large instance is minutes of replay, not seconds. A principal-level answer produces those numbers, then configures to meet them, rather than reciting settings. ## The configuration I would set **Local durability.** `appendonly yes`. `appendfsync everysec` as the default, because it bounds power-loss exposure at roughly one second at very little throughput cost. `appendfsync always` only when the workload's write rate and the storage device can absorb a synchronous flush per event-loop iteration; on network-attached storage this is often an order-of-magnitude throughput cut, so it must be measured, not assumed. Keep `aof-use-rdb-preamble yes` so the base loads fast, which is an RTO decision. **Snapshots for restore, not for durability.** Regular `BGSAVE` on a replica, shipped off-host with timestamped names, retention, and periodic rehearsed restores. AOF bounds the loss window; snapshots are what you use when someone runs the wrong command or the volume is gone. They answer different questions and you need both. **Redundancy across failure domains.** Replicas on different hosts, ideally different availability zones, each with its own persistence so a correlated restart does not come back empty. Automated failover via Sentinel or Cluster, configured with `min-replicas-to-write` so a partitioned master stops accepting writes it cannot replicate, which converts silent data loss into visible unavailability. Choosing that direction is a real decision to state out loud. **Host prerequisites.** `vm.overcommit_memory=1`, transparent huge pages off, and `maxmemory` low enough that dataset plus copy-on-write fits RAM. Persistence that cannot fork is persistence that is not happening; the failure is silent and shows only in `aof_last_bgrewrite_status` and a growing file. ## What they can still lose, stated plainly 1. **Up to about a second on power loss** with `everysec`, and more when the disk is lagging, which `aof_delayed_fsync` reveals. With `always`, an acknowledged write is fsynced first, though a device or controller with a volatile write cache can still acknowledge early. 2. **Acknowledged writes on failover.** This is the important one. Redis replication is asynchronous: the master replies to the client and streams to replicas afterwards. Promote a replica after a master dies and every write not yet shipped is gone, no matter how aggressively the master fsynced locally. No `appendfsync` value fixes this, because it is a distributed-systems property, not a disk property. 3. **Logical destruction.** `FLUSHALL`, a bad migration, or an application bug replicates to every replica within milliseconds. Only off-host snapshots, and ideally immutable ones, cover this. 4. **Time to recover.** A large AOF takes minutes to load. If the RTO is 30 seconds, persistence alone does not meet it; you need a warm standby. ## The tools that narrow the failover gap, and their limits `WAIT numreplicas timeout` blocks the calling client until N replicas have acknowledged the writes issued so far, returning how many did. Redis 7.0 added `WAITAOF numlocal numreplicas timeout`, which waits for the local AOF fsync and for replica fsyncs. Both are genuinely useful for the small subset of writes that truly must be confirmed, and both cost a round trip of latency on those writes. What they are not: synchronous commit. They confirm *after* the write was applied and acknowledged, they do not roll anything back if the confirmation fails, and they cannot help if the acknowledging nodes fail together. Presenting `WAIT` as making Redis a durable database is a red flag. ## The architectural recommendation For monetary data, I would place a durable, transactional store as the authority and use Redis for what it is exceptional at: latency, throughput and expressive data structures. Concretely, either write to the durable store first and use Redis as a cache and index, or write to Redis for speed and stream to durable storage with a reconciliation process that can rebuild Redis and detect divergence. Idempotency keys make the replay safe. If the team's constraint makes Redis genuinely the only store, then the deliverable is honesty in writing: the RPO per failure class, the RTO measured on real data, the alerting on persistence health (`aof_last_write_status`, `aof_last_bgrewrite_status`, `aof_delayed_fsync`, disk free space, replication lag), rehearsed failover and restore procedures, and explicit sign-off from whoever owns the money that a one-second and a failover-sized loss window are acceptable. A managed or enterprise offering with stronger replication guarantees is a legitimate part of that conversation, but it should be evaluated on the guarantees it documents, not on its marketing. ## How to close The strong answer names the residual risk before being asked. "With this configuration you lose at most about one second on a power cut, an unbounded amount on an ungraceful failover, and everything on a logical wipe unless we hold immutable off-host snapshots" is the sentence that distinguishes someone who has operated this from someone who has read the configuration file.
- Does WAIT make Redis writes durable?No. `WAIT` blocks until N replicas acknowledge the writes issued so far and returns how many did; it is confirmation after the fact, not synchronous commit. If fewer replicas acknowledge than you asked for, nothing is rolled back, and losing the acknowledging nodes simultaneously still loses the data. It narrows the failover gap for selected writes at a latency cost, which is worth doing, but it does not change the replication model.
- What does min-replicas-to-write buy you, and what does it cost?It makes a master refuse writes when fewer than the configured number of replicas are connected and within the lag threshold, so a partitioned master stops accepting writes that will be discarded when the other side is promoted. The cost is availability: the master becomes read-only during exactly the situations where you most want it to keep serving. It converts silent data loss into visible unavailability, which is usually the right trade for valuable data.
- How do you decide between appendfsync everysec and always here?By measuring. `always` fsyncs before replying, so an acknowledged write survives a power cut, but throughput becomes bounded by synchronous write latency, which on network-attached storage can cut it by an order of magnitude. I would benchmark both at production write rates on the actual storage, then check whether the value of removing a one-second window justifies the measured throughput and latency cost.
saying these in an interview costs you the question
- Answering with configuration directives without ever stating the residual loss
- Claiming appendfsync always plus replicas makes Redis equivalent to a durable transactional database
- Presenting WAIT or WAITAOF as synchronous commit
- Assuming replicas protect against a FLUSHALL or a bad application write
- Ignoring recovery time: a large AOF replays for minutes, which may already violate the RTO