Databases 7 min read

Understanding Redis Persistence: RDB and AOF Mechanisms

This article explains Redis's two persistence methods—RDB snapshots and AOF append‑only logs—including their operation, configuration options, advantages, disadvantages, and guidance on choosing the appropriate strategy for data durability and recovery.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
Understanding Redis Persistence: RDB and AOF Mechanisms

Redis is an advanced in‑memory key‑value database that supports persistence, offering rich data types such as strings, lists, sets, and sorted sets, and can perform server‑side set operations like union, intersection, and difference.

To maintain high performance, Redis keeps data in memory but periodically writes updated data to disk or an append‑only file, ensuring durability.

Redis provides two persistence strategies: RDB (snapshot) and AOF (append‑only file).

RDB Persistence : By default Redis creates binary snapshot files (dump.rdb) at configured intervals. When a snapshot is needed, Redis forks a child process that writes the dataset to a temporary RDB file; after successful write, the temporary file replaces the old one, leveraging copy‑on‑write.

Typical redis.conf snapshot settings: save 900 1 – if at least 1 key changes within 900 seconds, trigger a snapshot. save 300 10 – if at least 10 keys change within 300 seconds, trigger a snapshot. save 60 10000 – if at least 10,000 keys change within 60 seconds, trigger a snapshot.

Advantages of RDB include compact binary files suitable for backups and fast recovery, making it ideal for disaster‑recovery scenarios. Its drawbacks are longer intervals between snapshots (often minutes), which can lead to several minutes of data loss after a crash.

AOF Persistence : Every write command is appended to appendonly.aof. The persistence mode is enabled via appendonly yes. The appendfsync option controls how often data is flushed to disk: appendfsync yes – sync on every write (most durable, slower). appendfsync always – sync after each command (default disabled). appendfsync everysec – sync once per second (default, balances durability and performance).

AOF provides near‑real‑time durability, losing at most one second of data with the default every‑second fsync, while still maintaining good performance. Its disadvantages are larger file size compared to RDB and potentially slower write speed depending on the chosen fsync policy.

Comparison and Recommendation : RDB offers compact snapshots suitable for periodic backups and faster recovery, but may lose minutes of data. AOF records every write, offering higher durability with minimal data loss, at the cost of larger files and possible write overhead. Redis can enable both; on restart it prefers AOF for recovery, minimizing data loss.

For backup and disaster recovery, regularly generating RDB snapshots simplifies versioned backups, while enabling AOF ensures the most recent changes are retained.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

redisPersistenceData RecoveryBackupAOFRDB
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.