Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Compare Redis RDB snapshots and AOF persistence. How does each work, what data can you lose after a crash, and what is the recommended combination?

RDB writes point-in-time snapshots from a forked child process according to save rules; the files are compact and load fast, but a crash loses every write since the last snapshot. AOF appends every write command to a log and fsyncs it always, every second (the default, losing up to about one second) or when the OS decides, and is compacted by background rewrites, using multi-part files since Redis 7. The common combination is AOF everysec with the RDB preamble for durability and fast restarts, plus RDB files for backups, remembering that asynchronous replication can still lose acknowledged writes on failover.

Why this question is asked

Redis keeps its data in memory, so the question of what survives a crash or a restart is not academic. It decides whether a restart means a cold cache, logged-out users or lost queue items. Interviewers ask this question to see whether we understand how each persistence mode works underneath, because that explains both the data loss and the latency effects we see in production. In this answer, we will recap why Redis needs persistence, look at RDB and AOF step by step, see how AOF rewriting and the multi-part format work, combine them, and finish with what replication does and does not protect.

1A Quick Recap: Memory First, Disk Second

Redis serves every read and write from RAM. Persistence is a copy on disk that lets Redis reload its data after a restart. Redis offers two mechanisms, RDB and AOF, which can be used alone, together, or not at all. A pure cache often runs with neither, because its data can be rebuilt from the database.

2How RDB Snapshots Work

An RDB file is a compact binary dump of the whole dataset at one moment. Redis creates it with BGSAVE: the main process calls fork(), which creates a child process sharing the same memory pages. The child walks the data and writes it to a temporary file, then renames it to dump.rdb. Meanwhile the parent keeps serving clients.

Snapshots are triggered by save rules, such as save 3600 1 300 100 60 10000, meaning: snapshot if at least 1 key changed in an hour, 100 in five minutes, or 10,000 in a minute. We can also call BGSAVE ourselves.

Text
CONFIG GET save
# 1) "save" 2) "3600 1 300 100 60 10000"
BGSAVE
# Background saving started
INFO persistence
# rdb_last_bgsave_status:ok
# rdb_last_save_time:1730851200
INFO stats
# latest_fork_usec:182000 the fork took 182 ms

The strengths are clear: the file is small, ideal to copy for backups, and loading it at startup is fast. The weakness follows from being a snapshot: if Redis crashes at 10:59 and the last snapshot was at 10:00, every write of that hour is lost. There is also a cost during the snapshot, because fork takes time on a large instance and pages changed during the snapshot are copied, so memory use grows.

3How AOF Logging Works

The append-only file takes the opposite approach. Every write command Redis executes is appended to a log. On restart, Redis replays the log and ends up in the same state. How much we can lose depends on how often Redis forces the log from the operating system's buffers to the disk with fsync, set by appendfsync.

Java
CONFIG SET appendonly yes
CONFIG GET appendfsync
# "everysec"
# always: fsync after every write; safest, much slower
# everysec: fsync once per second in a background thread; default, lose about 1 s
# no: let the OS flush, often every 30 s; fastest, largest loss
What a crash can lose
SetupHow it writesData lost on crash
No persistencenothing on diskeverything
RDB onlysnapshot per save ruleall writes since the last snapshot
AOF appendfsync noOS flushes when it likesup to tens of seconds
AOF appendfsync everysecfsync once per secondup to about one second
AOF appendfsync alwaysfsync every writealmost nothing, at high cost
Failover to a replica can lose acknowledged writes in every row.

With everysec, a crash of the Redis process loses little or nothing, because written data is already in the OS buffers, and a power loss or kernel crash loses up to about the last second, slightly more if the disk is slow and fsync falls behind. That is why everysec is the usual balance between safety and speed.

4Rewriting the AOF and the Multi-Part Format

A log of every command grows forever: incrementing a counter a million times writes a million lines for one final value. So Redis rewrites the AOF in the background, again by forking a child that writes the current state as the shortest set of commands. It triggers automatically when the file has grown by auto-aof-rewrite-percentage, 100 percent by default, beyond its size after the last rewrite.

Since Redis 7.0 the AOF is multi-part. In the appendonlydir directory there is a base file, holding the state at the last rewrite, one or more incremental files with the commands since then, and a manifest file that lists them in order. A rewrite creates a new base and starts a new incremental file, then updates the manifest, so Redis no longer needs to buffer the writes that arrive during a rewrite in memory as older versions did.

With aof-use-rdb-preamble yes, the default since Redis 5, the base file is written in RDB format. That makes the AOF compact and fast to load, while the incremental files keep the per-second durability.

Step throughA Redis 7 AOF directory
  1. appendonly.aof.manifestlists the files in replay order
  2. appendonly.aof.3.base.rdbstate at the last rewrite, RDB format
  3. appendonly.aof.3.incr.aofcommands written since that rewrite

3 layers, from the top down. Step through them one at a time.

5Using Both, and What Replication Adds

A common production setup enables AOF with everysec for durability and keeps RDB snapshots for backups. When both exist, Redis loads the AOF at startup because it is more complete. RDB files, copied regularly to object storage, give us point-in-time backups that are easy to restore into a new instance.

But there is a catch that persistence cannot fix. Replication from a primary to its replicas is asynchronous: the primary acknowledges a write to the client before replicas have it. If the primary fails and a replica is promoted, writes that had not reached the replica are lost, however carefully the old primary persisted them. The WAIT command lets a client block until a number of replicas have received its writes, which narrows the window, but it does not make a failover lossless, because the new primary is not guaranteed to be one of those replicas.

6Follow-up questions

What happens to latency during BGSAVE on a large instance?

Two things. The fork itself blocks the main thread while the kernel copies the page tables, which can take tens or hundreds of milliseconds on an instance of tens of gigabytes; latest_fork_usec in INFO stats shows it. Then, while the child writes, every page the parent modifies is copied, which costs CPU and memory and can cause more spikes, especially with transparent huge pages enabled, so we disable them.

Which persistence should a pure cache use?

Often none. If the data can be reloaded from the database, persistence only adds fork costs and disk I/O. Some teams keep an occasional RDB snapshot so that a restart starts warm, which is a reasonable compromise when a cold cache would overload the database.

Is appendfsync always ever worth it?

Rarely. It turns every write into a disk sync, which can reduce throughput dramatically, and it still does not protect against loss on failover because replication is asynchronous. If data is that critical, it usually belongs in a database designed for synchronous durability.

7Conclusion

In this answer, we saw that RDB takes compact point-in-time snapshots through a forked child, fast to load but losing all writes since the last snapshot, while AOF logs every write and fsyncs per the appendfsync setting, losing up to about one second with the default everysec. AOF is compacted by background rewrites and since Redis 7 is stored as a base file, incremental files and a manifest, with an RDB preamble by default. Using both is common, and asynchronous replication means a failover can lose acknowledged writes regardless, which WAIT reduces but does not remove.

What to say in the interviewAbout 80 seconds aloud

Open with

RDB and AOF solve the same problem in opposite ways. RDB takes point-in-time snapshots: BGSAVE forks a child process that writes the whole dataset to a compact file, triggered by save rules like 'a hundred changes in five minutes'.

Then, if they want more

The file is small and loads fast, which is great for backups and restarts, but after a crash I lose every write since the last snapshot, and the fork plus copy-on-write cost memory and latency on big instances. AOF appends every write command to a log and replays it on restart.

The appendfsync setting decides the loss: always fsyncs every write and is slow, everysec is the default and loses up to about a second, and no leaves it to the OS.

The log is compacted by background rewrites, and since Redis 7 it is multi-part: a base file, incremental files and a manifest, and with aof-use-rdb-preamble the base is in RDB format. The usual recommendation is both: AOF everysec for durability, and RDB snapshots copied off the machine for backups.

And I always add that replication is asynchronous, so a failover can lose acknowledged writes whatever persistence I choose; WAIT reduces that window but does not eliminate it.

About this answer

Last updated
12 November 2026
Versions it names
Redis 7, Redis 5
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 "Compare Redis RDB snapshots and AOF persistence. How does each work, what data can you...": https://scrivio-interview-library.netlify.app/databases/redis/49dcbea1dd/