← Lessons

quiz vs the machine

Gold1400

Databases

Redis Persistence RDB and AOF

Two ways an in memory store survives a restart, trading speed for durability.

5 min read · core · beat Gold to climb

Surviving a Restart

Redis keeps data in memory, so without persistence a restart loses everything. It offers two mechanisms that can run alone or together.

RDB Snapshots

An RDB snapshot writes the whole dataset to a compact file at intervals. It forks the process and dumps memory to disk. Snapshots are fast to load and small, making them great for backups. The downside is that any writes after the last snapshot are lost on a crash.

Append Only File

The AOF logs every write command as it happens. On restart Redis replays the log to rebuild state. With frequent flushing AOF loses at most a second or so of writes, giving much better durability. The cost is a larger file and slower restart, though Redis periodically rewrites the log to keep it compact.

Choosing

  • Use RDB for fast backups and quick recovery when some data loss is tolerable.
  • Use AOF when durability matters most.
  • Run both to get fast restarts from RDB plus the safety of the AOF log.

Key idea

RDB snapshots are compact and fast but lose writes since the last dump, while AOF logs every command for stronger durability at the cost of size and restart speed.

Check yourself

Answer to earn rating on the learn ladder.

1. What does an RDB snapshot store?

2. Why does AOF generally give better durability than RDB?

3. What is a downside of AOF compared to RDB?