Databases 13 min read

Understanding Redis Persistence: RDB, AOF, and Hybrid Strategies

This article explains why Redis, an in‑memory database, needs persistence, compares the four official persistence options (RDB, AOF, RDB+AOF, and no persistence), details their configurations, performance trade‑offs, and introduces the hybrid RDB+AOF approach for balanced durability and speed.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Understanding Redis Persistence: RDB, AOF, and Hybrid Strategies

During a backend interview, a candidate was asked how to recover data when Redis crashes, highlighting the need to understand Redis persistence strategies.

Redis stores data in memory, so a crash would lose all data; restoring from a traditional database can overload it, making persistence essential.

The official persistence mechanisms are:

RDB (Redis Database) : creates point‑in‑time snapshots saved to dump.rdb using SAVE (blocking) or BGSAVE (forked child process). It relies on copy‑on‑write to avoid blocking writes during snapshotting.

AOF (Append‑Only File) : logs every write command, which can be replayed on restart. Write‑back policies include always , everysec , and no .

RDB + AOF : combines both methods.

No persistence : disables durability, rarely used.

RDB configuration examples (in redis.conf )

# Periodic snapshot format
save <seconds> <changes>
# Default settings
save 900 1
save 300 10
save 60 10000
# Disable snapshots
save ""

Key points about RDB:

Fast recovery, small compressed files, but not second‑level durability.

Frequent snapshots increase disk I/O and fork overhead.

AOF configuration example (in redis.conf )

# Enable AOF persistence
appendonly no
# AOF file name
appendfilename "appendonly.aof"
# Sync policy (default everysec)
appendfsync everysec
# Disable fsync during rewrite
no-appendfsync-on-rewrite no
# Rewrite trigger
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
# Truncate on load errors
aof-load-truncated yes
# Incremental fsync during rewrite
aof-rewrite-incremental-fsync yes

AOF pros and cons:

Provides near‑second durability (especially with always ), but incurs write latency.

File can grow large; rewrite ( BGREWRITEAOF ) compacts it but may be time‑consuming.

Hybrid RDB+AOF (Redis 4.0+): periodic snapshots are taken, while AOF records commands between snapshots. This reduces fork frequency and AOF size, offering fast recovery from snapshots and minimal data loss from the AOF log.

Recommendation: use the hybrid approach when data loss is unacceptable; otherwise choose RDB for tolerable loss or AOF with everysec for a balance between performance and reliability.

databaseRedisPersistenceAOFRDBHybrid
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login 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.