Redis  

Redis Persistence Explained: RDB vs AOF vs Hybrid Persistence (Which One Should You Use?)

Why Persistence Matters in Redis

Redis is famous for being fast. Blazing fast. But speed alone does not run production systems. At some point, your Redis process will crash, your VM will reboot, or your container will be rescheduled. When that happens, the first question you will ask is simple:

Did my data survive?

Redis keeps everything in memory, which makes it fast. But memory is volatile. That is where persistence comes in. Persistence is how Redis writes data to disk so it can recover after a restart.

  • Redis gives you three real options:

  • RDB snapshots

  • AOF logs

  • Hybrid persistence (RDB + AOF)

Each exists because different systems have different tolerance for data loss, startup time, and write overhead. There is no universal best choice. There is only a correct choice for your workload.

RDB Persistence Explained (Snapshot-Based)

RDB stands for Redis Database Backup. Conceptually, it is very simple. At specific intervals, Redis takes a snapshot of the entire dataset in memory and writes it to disk as a compact binary file called dump.rdb. That snapshot represents Redis at a moment in time.

How RDB Works Internally

  • Redis forks a child process

  • The child process writes the entire dataset to disk

  • The parent process continues serving reads and writes

  • Once complete, the old snapshot is replaced

This design is important. Redis does not stop serving traffic while creating snapshots. The OS handles copy-on-write memory pages efficiently, so performance impact is usually low unless your dataset is massive.

Advantages of RDB

Very fast Redis restarts
Compact file size
Minimal disk I/O during normal operation
Simple to reason about
Excellent for backups and disaster recovery

If Redis crashes, it loads one file and is immediately usable.

Downsides of RDB

You can lose data between snapshots
Snapshots are point-in-time, not continuous
Forking can cause memory spikes on very large datasets

If your snapshot runs every 5 minutes and Redis crashes at minute 4, you lose 4 minutes of data. For some systems, that is acceptable. For others, it is not.

When RDB Makes Sense

Cache data you can recompute
Session data with low criticality
Leaderboards and analytics counters
Read-heavy systems
Disaster recovery backups

RDB is simple, fast, and reliable for many use cases. It is also the default choice for people who treat Redis as a cache rather than a source of truth.

AOF Persistence Explained (Append-Only Logging)

AOF takes a very different approach.

Instead of saving snapshots, Redis logs every write operation to a file. That file is replayed during startup to rebuild the dataset.

Think of AOF like a transaction log.

SET user:1 "Mahesh"
INCR page_views
DEL temp:token

Every change is recorded in order.

How AOF Works

Redis executes a write command
The command is appended to the AOF file
The command may be flushed immediately or later
On restart, Redis replays the log

You control how frequently Redis flushes data to disk.

Every write
Every second
OS controlled

This lets you balance durability vs performance.

Advantages of AOF

Much lower risk of data loss
Fine-grained durability control
Human-readable log format
Safer for critical data

With AOF set to everysec, the worst-case data loss is about one second. For many systems, that is good enough.

Downsides of AOF

Larger files than RDB
Slower restarts for large datasets
More disk I/O
Requires rewrite and compaction

Over time, the AOF file grows. Redis periodically rewrites it to remove redundant commands. This rewrite process is safe but adds complexity.

When AOF Makes Sense

Financial counters
Job queues
User state that must not be lost
Rate limiting data
Distributed locks

If Redis data matters, AOF is often the better choice.

Hybrid Persistence (RDB + AOF)

Redis eventually acknowledged that neither RDB nor AOF alone is perfect.

Hybrid persistence combines the strengths of both.

How Hybrid Persistence Works

Redis creates an RDB snapshot
Then appends AOF commands after the snapshot
On restart, Redis loads the snapshot first
Then replays only the recent AOF entries

This dramatically improves restart times while maintaining strong durability.

Why Hybrid Is Powerful

Fast startup
Lower AOF replay cost
Reduced disk usage
Better crash recovery

Hybrid mode is now the recommended approach for many production systems because it balances safety and performance without major downsides.

Performance Impact Comparison

RDB has almost zero impact on write latency during normal operations.

AOF adds write overhead depending on fsync policy.

Every write fsync is the safest but slowest
Every second is the sweet spot
OS controlled is risky under crash scenarios

Hybrid mode keeps write overhead close to AOF but improves recovery speed.

For high-throughput systems, this tradeoff matters.

Durability Comparison (Straight Talk)

RDB durability is weak by design
AOF durability is strong
Hybrid durability is strong

If Redis is your system of record, RDB alone is a bad idea.

If Redis is a cache, AOF might be unnecessary overhead.

This is not academic. Many production outages come from misunderstanding this exact tradeoff.

Startup and Recovery Time

RDB loads fast
AOF loads slow for large datasets
Hybrid loads fast

If you have millions of keys and use pure AOF, restarts can take minutes. In containerized environments, that matters.

Disk Usage

RDB is compact
AOF grows continuously
Hybrid is balanced

If disk space is limited, RDB wins. If data safety matters, disk is cheap compared to data loss.

Real-World Production Recommendations

Here is the blunt advice most Redis experts eventually converge on.

Use RDB only when Redis is a cache
Use AOF when Redis holds critical state
Use Hybrid for most serious production systems

If you are unsure, Hybrid is the safest default.

Common Mistakes Engineers Make

Assuming Redis persistence is enabled by default
Using RDB for critical data
Forgetting to test recovery scenarios
Not monitoring disk usage for AOF
Running Redis in production without persistence at all

Persistence is not something you configure once and forget. It is something you validate by killing Redis and watching it recover.

Summary

Redis persistence is not about choosing the “best” option. It is about choosing the least wrong option for your workload.

RDB prioritizes speed and simplicity
AOF prioritizes durability
Hybrid prioritizes balance

Good architects do not argue ideology. They match tools to failure modes.

If Redis going down should be boring, persistence must be designed intentionally.