Scrivio Interview library
ScenarioFoundations6 min read · updated 13 November 2026

To speed up a busy Redis primary, a team turned off both RDB and AOF on it and kept persistence only on its two replicas. A process supervisor restarts the primary automatically whenever it exits.

The primary crashed at night and was back within two seconds. What happened to the data on all three nodes, and how should the setup be configured instead?

The primary restarted empty because it had no RDB or AOF to load, and since it was back before any failover could start, both replicas reconnected to it, performed a full sync and replaced their data with its empty dataset, so all three nodes lost everything. A primary without persistence must never restart automatically; better, keep persistence on the primary (AOF everysec or RDB snapshots) and make it cheaper with fast disks, and copy backups off the host and test restores, because replication copies mistakes as faithfully as good data.

Why this question is asked

This is one of the most instructive Redis failures because every individual decision looked reasonable: persistence slowed the primary, replicas already had copies, and a supervisor restarting crashed processes is normally good practice. Combined, they turn a two-second crash into total data loss. Interviewers ask it to check whether we understand that replicas follow the primary, whatever it holds, and that failover cannot react to a restart faster than its detection time. In this answer, we will replay the night step by step, see why Sentinel could not help, fix the configuration, and add backups that protect against what replication cannot.

1A Quick Recap: Persistence and Replicas

Redis keeps data in memory. RDB persistence writes periodic snapshots to disk, and AOF (append-only file) logs every write, so after a restart Redis can load its data back. With both turned off, a restarted Redis starts with an empty dataset.

Replicas copy whatever their primary holds. When a replica connects and cannot continue from where it was, it performs a full synchronisation: it discards its own dataset and loads a snapshot of the primary's. It does not judge whether that snapshot is sensible. An empty primary produces an empty snapshot.

2What Happened During the Night

The primary crashed and its supervisor restarted it within two seconds. With no RDB or AOF to load, it came up with zero keys and a new replication ID, since a fresh process has no record of its previous history. The replicas, which had briefly lost their connection, reconnected to the same address and asked to continue with PSYNC. The primary did not recognise their replication ID, so it answered with a full resync, sent its empty snapshot, and both replicas flushed their copies and loaded it. A few seconds after the crash, all three nodes were empty and fully in sync.

Step throughTwo seconds that emptied all three nodes
SupervisorPrimaryReplica 1Replica 2
crash
restart after 2 s, nothing to load
PSYNC old-id offset
FULLRESYNC: empty snapshot
PSYNC old-id offset
FULLRESYNC: empty snapshot
flush and load: 0 keys
flush and load: 0 keys

8 messages in order. Play them, or step through them one at a time.

3Why Sentinel Could Not Help

Sentinel declares a primary down only after it fails to answer for down-after-milliseconds, typically 5 to 30 seconds. Here the primary was answering again after two seconds, so as far as Sentinel was concerned, nothing had happened. There was no failover, no promotion of a replica with good data, nothing to stop the replicas from following the empty primary. Even a perfectly configured Sentinel cannot react to a restart that is faster than its detection time, and it does not look at whether the primary's data makes sense.

Shell
redis-cli -h replica1 INFO replication
# role:slave
# master_link_status:up
# master_sync_in_progress:0
redis-cli -h replica1 DBSIZE -- (integer) 0
redis-cli -h primary INFO stats | grep sync_full
# sync_full:2 -- two full syncs right after the restart

4A Primary Without Persistence Must Not Restart Itself

If the team insists on running the primary without persistence, the one hard rule is that it must not come back automatically as a primary. The supervisor should leave it down after a crash, so that Sentinel detects the failure, promotes a replica with a full dataset, and the old primary rejoins later only as a replica of the new one. This is the configuration the Redis documentation itself warns about: persistence off plus automatic restarts is the dangerous combination.

Step throughSafe handling of a primary crash
  1. Primary process exits
  2. Does it have persistence (AOF or RDB)?
    YesRestart: it reloads its dataNoDo not restart automatically
  3. Sentinel detects the failureafter down-after-milliseconds
  4. Replica with full data is promoted
  5. Old node rejoins as a replicacopies the good dataset

5 steps in order. Play them, or step through them one at a time.

5The Better Configuration

The better answer is to keep persistence on the primary and make it cheaper rather than removing it. AOF with appendfsync everysec loses at most about a second of writes and costs one fsync per second; RDB snapshots every few minutes cost a fork. Both are much cheaper on fast dedicated disks such as local NVMe, and AOF rewrites can be made less frequent by raising auto-aof-rewrite-percentage. Diskless replication keeps full syncs from touching the disk at all. If the remaining cost is still too high, the primary is likely overloaded and needs sharding, not less safety.

Text
# primary redis.conf
appendonly yes
appendfsync everysec # at most about 1 s of writes lost on a crash
auto-aof-rewrite-percentage 200 # rewrite less often
save 900 1 # plus an RDB snapshot for backups
repl-diskless-sync yes # full syncs do not write RDB to disk

Notice that this also removes the danger of the supervisor: a primary with AOF that restarts after two seconds comes back with its data, and the replicas continue as before.

6Backups Protect Against What Replication Cannot

Replication copies deletions, bugs and an empty dataset as faithfully as good data, so it is never a backup. Copy RDB files off the host regularly, for example hourly to object storage with a retention of several days, and test restores: once a month, load a backup into a separate instance and check key counts and a few known values. Only a tested restore proves that a backup exists.

7Follow-up questions

Which INFO fields would have shown the replicas had resynced?

On the primary, INFO stats would show sync_full increased by two right after the restart, and INFO server a very small uptime_in_seconds. On the replicas, INFO replication would show a new master_replid, and INFO keyspace would show the key count dropping to zero, which DBSIZE confirms. An alert on a sudden fall in key count, or on sync_full increasing outside maintenance, would have caught it within a minute.

Would replica-serve-stale-data or other replica settings have saved the data?

No. They control how a replica answers while disconnected, not whether it accepts a full sync. Once it reconnects and the primary sends a snapshot, the replica replaces its data.

Is it ever acceptable to run without persistence?

For a pure cache whose contents can be rebuilt from a database, yes, as long as everyone agrees that an empty cache after a crash is acceptable and the system can handle the load of refilling it. That is a decision about the data, not a tuning trick for a busy primary.

8Conclusion

In this answer, we saw that the primary restarted empty because it had no persistence, came back faster than Sentinel's detection time, and forced both replicas into a full sync that replaced their data with nothing. We made the rule that a primary without persistence must never restart automatically, preferred keeping AOF or RDB on the primary and making it cheaper with fast disks and fewer rewrites, and added off-host backups with tested restores, since replication copies mistakes as faithfully as data.

What to say in the interviewAbout 90 seconds aloud

Open with

All three nodes lost their data. The primary had neither RDB nor AOF, so when the supervisor restarted it two seconds after the crash, it had nothing to load and came up empty, with a new replication ID.

Then, if they want more

The replicas reconnected to the same address, the primary did not recognise their history, so it answered with a full resync and sent them its empty snapshot, and both replicas flushed their good copies and loaded nothing.

Sentinel could not help, because the primary was answering again long before down-after-milliseconds expired, so no failover ever started, and replicas simply copy whatever the primary holds. The hard rule is that a primary without persistence must never restart automatically.

After a crash it should stay down, so a replica with the full dataset is promoted, and the old node rejoins only as a replica.

But my preferred fix is to keep persistence on the primary, AOF with appendfsync everysec or regular RDB snapshots, with diskless replication, and reduce the cost with fast dedicated disks and fewer rewrites instead of turning it off; if that is still too expensive, the primary needs sharding.

Finally, I would copy RDB backups off the host regularly and test restores, because replication copies deletions and mistakes just as faithfully as good data, so it is never a backup.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Redis documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "The primary crashed at night and was back within two seconds. What happened to the data...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/8e128fcf61/