principlejavascriptredisMajor
Redis persistence: RDB snapshots vs AOF — choosing and combining
Viewed 0 times
redisRDBAOFpersistencedurabilityBGSAVEappendfsyncsnapshotwrite-ahead log
Error Messages
Problem
Using RDB-only persistence risks losing minutes of writes on crash. Using AOF-only with fsync=always kills throughput. Disabling persistence entirely on a cache-intended instance then using it for data that matters causes silent data loss.
Solution
For most production systems: enable both RDB and AOF. Use AOF with appendfsync everysec (1-second durability window) and auto-rewrite thresholds. Take RDB snapshots for fast restarts and backups. Pure cache instances can disable both safely.
Why
RDB provides compact point-in-time snapshots for fast restarts but loses data since the last snapshot. AOF logs every write and can replay to exact state but is larger and slower to restore. Combined mode gets fast startup (RDB) with recent-write protection (AOF).
Gotchas
- BGSAVE forks the process — on large datasets this can cause latency spikes due to copy-on-write memory pressure
- AOF rewrite (BGREWRITEAOF) also forks; schedule it during low-traffic periods
- appendfsync always provides strong durability but drops throughput by 10-100x
- After a crash, if both RDB and AOF exist, Redis loads the AOF file (more complete data)
Code Snippets
redis.conf recommended combined persistence settings
# redis.conf
save 900 1 # RDB: snapshot if 1 change in 900s
save 300 10
save 60 10000
appendonly yes
appendfsync everysec # 1-second durability window
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mbRevisions (0)
No revisions yet.