What if your data vanished in a blink--how would you get it back without losing everything?
RDB vs AOF comparison in Redis - When to Use Which
Imagine you run a busy cafe and keep track of every order by writing it down on paper. If the paper gets lost or damaged, you lose all your records and have to start over.
Writing orders manually is slow and risky. You might forget to write some orders, lose the paper, or make mistakes. Recovering lost data is almost impossible, causing frustration and lost customers.
Redis uses two ways to save data safely: RDB snapshots and AOF logs. RDB takes quick pictures of your data at intervals, while AOF records every change step-by-step. Together, they keep your data safe and easy to restore.
Write every order on paper and hope it stays safe.Use RDB snapshots for quick backups and AOF logs for detailed recovery.
This lets you recover your data quickly and reliably, even if something goes wrong, so your service never misses a beat.
A popular online game uses RDB to save player progress every few minutes and AOF to record every move instantly, ensuring no progress is lost even if the server crashes.
Manual tracking is slow and risky.
RDB creates fast snapshots of data.
AOF logs every change for detailed recovery.
Practice
Solution
Step 1: Understand RDB persistence
RDB saves the dataset by creating snapshots at set intervals.Step 2: Compare with AOF
AOF logs every write operation, not snapshots.Final Answer:
RDB (Redis Database snapshot) -> Option BQuick Check:
Snapshot saving = RDB [OK]
- Confusing AOF with snapshot saving
- Thinking both save snapshots
- Believing neither saves snapshots
Solution
Step 1: Identify AOF enabling command
The command to enable AOF isCONFIG SET appendonly yes.Step 2: Check other options
CONFIG SET save "900 1 300 10 60 10000" sets RDB save intervals, C disables RDB compression, D sets memory eviction policy.Final Answer:
CONFIG SET appendonly yes -> Option AQuick Check:
Enable AOF = appendonly yes [OK]
- Confusing RDB save command with AOF
- Using unrelated config commands
- Forgetting to set appendonly to yes
Solution
Step 1: Understand AOF with fsync everysec
With fsync set to 'everysec', Redis writes AOF data to disk every second.Step 2: Analyze durability implications
This means data could be lost if Redis crashes within the last second before fsync.Final Answer:
Data is saved only at intervals, risking data loss of last seconds -> Option AQuick Check:
AOF everysec fsync = possible 1-second data loss [OK]
- Assuming every write is immediately saved
- Thinking data is never saved automatically
- Confusing with no persistence
Solution
Step 1: Understand RDB and AOF coexistence
Redis supports both RDB and AOF, preferring to load AOF first on restart if available.Step 2: Analyze data loss causes
With both enabled, if data is missing after a crash, the most likely cause is AOF corruption, causing fallback to the older RDB snapshot and loss of recent changes.Final Answer:
AOF file is corrupted and Redis cannot load it -> Option DQuick Check:
Data loss with both = AOF corrupted [OK]
- Believing Redis can't use both persistences
- Thinking RDB interval too long is the cause
- Forgetting to restart Redis
Solution
Step 1: Match recovery speed and data loss tolerance
RDB snapshots every 60 seconds allow fast recovery but may lose up to 1 minute of data.Step 2: Compare with AOF options
AOF with fsync always is slower but safer; both enabled adds overhead; disabling persistence risks total data loss.Final Answer:
Enable RDB snapshots every 60 seconds, disable AOF -> Option CQuick Check:
Fast recovery + 1 min loss = RDB every 60s [OK]
- Choosing AOF for fast recovery despite slower startup
- Enabling both causing unnecessary overhead
- Disabling persistence risking total data loss
Ready to prove it?
Pass the test and this pattern moves unknown
