Databases 8 min read

Understanding Redis Persistence: RDB, AOF, and Hybrid Persistence

This article explains Redis's three persistence mechanisms—RDB snapshots, AOF append‑only logs, and their hybrid mode—detailing trigger conditions, configuration options, advantages, disadvantages, and practical guidance for selecting the appropriate method in production environments.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Understanding Redis Persistence: RDB, AOF, and Hybrid Persistence

Redis is an in‑memory database that offers high performance but requires persistence mechanisms to protect data against loss; it supports three persistence approaches: RDB (snapshot), AOF (append‑only file), and a hybrid RDB+AOF mode.

RDB (Redis Database) creates binary snapshots of the dataset at configured intervals. It can be triggered manually with save (blocking) or bgsave (background), or automatically via redis.conf settings such as:

save 3600 1   # at least one write in 3600 seconds
save 300 100  # at least 100 writes in 300 seconds
save 60 10000 # at least 10000 writes in 60 seconds

Common RDB configuration parameters include:

# RDB file name, default dump.rdb
dbfilename dump.rdb
# Directory for RDB file, default current directory
dir ./
# Enable compression
rdbcompression yes
# Stop writes on background‑save error
stop-write-on-bgsave-error
# Verify checksum on load
rdbchecksum yes

Advantages of RDB are compact binary files, good performance, fast recovery for large datasets, and suitability for backups; disadvantages are potential data loss between snapshots and brief pauses caused by forked processes.

AOF (Append Only File) logs every write command to a text file, ensuring full data durability. Over time the file can grow large, so Redis rewrites it to remove redundancy. Configuration example:

# AOF file name
appendfilename "appendonly.aof"
# Enable AOF
appendonly yes
# Sync policy (everysec is a common trade‑off)
appendfsync everysec
# Rewrite thresholds
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

AOF provides better data integrity and easier readability, but the file is larger and write‑sync overhead can reduce performance compared with RDB.

Hybrid RDB+AOF combines both methods: during an AOF rewrite, Redis writes an RDB snapshot at the beginning of the AOF file, then appends subsequent commands. This yields fast restart like RDB while retaining AOF’s durability. Enabling it requires:

# Enable RDB snapshot triggers (same as above)
save 3600 1
save 300 100
save 60 10000
# Enable AOF
appendonly yes
# Sync policy
appendfsync everysec
# Activate hybrid mode
aof-use-rdb-preamble yes

The article concludes that, for most production scenarios, the hybrid mode offers the best balance of safety and performance; RDB alone is acceptable when occasional data loss is tolerable, while using only AOF is generally not recommended. If Redis is used purely as a cache, persistence can be disabled for maximum speed.

databaseRedisconfigurationPersistenceAOFRDBHybrid
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

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.