Module Review: Persistence & Durability

You have mastered the art of keeping data safe in Redis. From simple snapshots to complex append-only logs, you now understand the trade-offs between performance and durability.

1. Key Takeaways

  1. RDB (Snapshots): Great for backups and fast restarts. Uses fork() and Copy-On-Write (COW) to save data in the background. Risk: Data loss since the last snapshot.
  2. AOF (Append Only File): Logs every write command. More durable than RDB. Uses fsync policies (always, everysec, no) to balance safety and speed. Risk: Large file sizes (mitigated by rewrites).
  3. COW Memory Spike: Triggering a snapshot can double memory usage in the worst case if every page is modified during the save.
  4. Hybrid Persistence: The best of both worlds. An AOF file that starts with an RDB snapshot header. Fast load + high durability.

2. Interactive Flashcards

Test your knowledge before the interview.

What system call does Redis use for background saving?
fork(). It creates a child process that shares memory pages with the parent via Copy-On-Write (COW).
Which AOF fsync policy is the default and recommended?
everysec. It fsyncs once per second, balancing performance with a max 1-second data loss window.
What is the main danger of RDB snapshots?
Data loss. If Redis crashes, you lose all data written since the last successful snapshot.
How does AOF Rewrite reduce file size?
It reads the *current* memory state and generates the minimal set of commands needed to recreate it, discarding obsolete logs.
What is Hybrid Persistence?
A feature where the AOF file starts with an RDB snapshot (for speed) and continues with AOF logs (for recent durability).

3. Persistence Cheat Sheet

Command / Config Description
BGSAVE Trigger a background RDB snapshot manually.
SAVE Trigger a blocking RDB snapshot (Donโ€™t use in prod!).
BGREWRITEAOF Trigger an AOF rewrite manually.
appendonly yes Enable AOF persistence.
appendfsync everysec Sync AOF to disk every second.
save 900 1 Auto-save RDB if 1 key changes in 900 seconds.
aof-use-rdb-preamble yes Enable Hybrid Persistence (Redis 4.0+).
stop-writes-on-bgsave-error If RDB fails, stop accepting writes (Safety).

4. Next Steps

Now that your data is durable, how do we scale beyond a single node?


Redis Glossary

Confused by a term? Check the full glossary.