Redis Persistence Mechanism

Redis provides two main persistence mechanisms, RDB and AOF, and version 4.0 added hybrid persistence.

RDB is snapshot persistence. At a given point in time, it dumps all in-memory data into a binary file. Recovery is fast and the file is small, which makes it good for backups and disaster recovery. The downside is that if Redis crashes, any data written since the last snapshot is lost. For example, with a snapshot every 5 minutes, you could lose up to 5 minutes of data.

AOF is log-based persistence. Every write command is appended to a file. Data safety is high, with at most about 1 second of data lost. The downsides are that the file is large, and recovery requires replaying every command, which can be very slow when there’s a lot of data.

Hybrid persistence combines the two. During an AOF rewrite, Redis first writes an RDB snapshot, then appends later commands in AOF format. On recovery, it loads the RDB part first and then replays the AOF part. This gives you both fast recovery and strong data safety.