Hybrid Persistence: The “Have Your Cake and Eat It Too” Solution
For years, Redis users faced a tough choice:
- RDB: Fast startup, compact files, but risk losing minutes of data.
- AOF: minimal data loss, but slow startup (replaying millions of logs) and huge files.
In Redis 4.0, a third option was introduced: Hybrid Persistence.
1. How It Works
Hybrid persistence changes how the AOF Rewrite works.
Instead of writing a sequence of SET commands to recreate the dataset, the rewrite process:
- Takes an RDB Snapshot of the current memory.
- Writes this binary RDB data to the beginning of the AOF file.
- Appends standard AOF Logs for any new writes that happen during the rewrite.
The Structure of a Hybrid AOF File
[ RDB Binary Header ] <-- 99% of your data (Compact, Fast to load)
[ AOF Log Entry 1 ] <-- Recent writes during rewrite
[ AOF Log Entry 2 ]
...
When Redis restarts:
- It loads the RDB header extremely fast.
- It replays the small AOF tail to catch up to the latest state.
Result: You get RDB’s fast startup and AOF’s durability.
2. Interactive: Choose Your Strategy
Not sure which persistence mode to use? Use this selector to find the best configuration for your use case.
Recommendation: ...
Select options to get a recommendation.
# redis.conf
...
3. Enabling Hybrid Persistence
In modern Redis versions (5.0+), this is enabled by default.
# redis.conf
# 1. Enable AOF
appendonly yes
# 2. Enable RDB Preamble
aof-use-rdb-preamble yes
[!IMPORTANT] If you are upgrading from an older Redis version, check that
aof-use-rdb-preambleis set toyes.
4. Summary: The Evolution of Persistence
| Era | Technology | Characteristics |
|---|---|---|
| Redis 1.0+ | RDB | Simple snapshots. Fast but risky. |
| Redis 2.0+ | AOF | Append logs. Safe but slow and bloated. |
| Redis 4.0+ | Hybrid | RDB + AOF. The gold standard. |
Now that your data is safe, let’s review everything we have learned.