AboutBlogContact
DatabasesOctober 15, 2009 2 min read 26

Redis: RDB vs. AOF Persistence (2009)

AunimedaAunimeda
📋 Table of Contents

Redis: RDB vs. AOF Persistence

Salvatore Sanfilippo (antirez) has given us the fastest key-value store on the planet. But Redis is "ephemeral" by default. If you want your data to survive a restart, you have two main options.

RDB (Redis Database Backup)

RDB is a compact point-in-time snapshot of your dataset. It's great for backups and fast restarts.

# redis.conf snapshotting rules
save 900 1      # Save after 900s if 1 key changed
save 300 10     # Save after 300s if 10 keys changed

The magic of RDB is fork(). Redis forks a child process, which writes the entire memory state to disk while the parent continues to serve requests. Since it uses "copy-on-write," the memory overhead is manageable unless you have a massive write volume.

AOF (Append Only File)

AOF logs every write operation received by the server. It's much more durable than RDB.

appendonly yes
appendfsync everysec

With everysec, you lose at most one second of data. However, the AOF file grows indefinitely. This is where AOF Rewrite comes in. Redis can recreate the AOF in the background by reading the current state of memory and writing the shortest sequence of commands needed to rebuild it.

Which one?

If you care about performance and can lose a few minutes of data, use RDB. If you need maximum durability, use both. Just remember that if both are enabled, Redis will use the AOF on startup because it's guaranteed to be more complete.

Read Also

CouchDB: Scaling with MapReduce and Incremental Views (2009)aunimeda
Databases

CouchDB: Scaling with MapReduce and Incremental Views (2009)

2009 is the year of the 'NoSQL' movement. CouchDB is leading the charge with its document-based storage and powerful MapReduce indexing system.

MongoDB: When Your Data Doesn't Fit in a Tableaunimeda
Databases

MongoDB: When Your Data Doesn't Fit in a Table

The 10gen team has released MongoDB. It's 'humongous' (supposedly), it's NoSQL, and it uses JSON. Is the relational era over?

InfluxDB: TSM Engine and the Cardinality Trap (2014)aunimeda
Databases

InfluxDB: TSM Engine and the Cardinality Trap (2014)

Moving from LevelDB to TSM was a bold move. Let's see how InfluxDB handles millions of series and why high cardinality is your worst enemy.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Get Consultation All articles