Bird
Raised Fist0
Redisquery~10 mins

RDB vs AOF comparison in Redis - Visual Side-by-Side Comparison

Choose your learning style10 modes available
Concept Flow - RDB vs AOF comparison
Start Redis Server
↓
Data Changes Occur
↓
RDB Snapshot Triggered?
Yes→Save Data Snapshot to Disk
↓
Wait for Next Trigger
↓
AOF Append Command?
Yes→Append Command to AOF File
No↓
Wait for Next Command
Redis saves data using two methods: RDB snapshots save full data at intervals, AOF logs every write command as it happens.
Execution Sample
Redis
SET key1 value1
INCR counter
SAVE
SET key2 value2
BGREWRITEAOF
Shows how Redis commands affect RDB snapshots and AOF logs during data changes.
Execution Table
StepCommandRDB ActionAOF ActionResulting State
1SET key1 value1No snapshotAppend 'SET key1 value1'key1=value1 in memory, AOF has 1 command
2INCR counterNo snapshotAppend 'INCR counter'counter=1 in memory, AOF has 2 commands
3SAVECreate RDB snapshot fileNo appendRDB file saved, memory unchanged
4SET key2 value2No snapshotAppend 'SET key2 value2'key2=value2 in memory, AOF has 3 commands
5BGREWRITEAOFNo snapshotRewrite AOF file compactlyAOF file rewritten with current data commands
6No new commandNo snapshotNo appendWaiting for next commands
💡 No new commands, waiting for next data changes
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
Memory Dataempty{key1: value1}{key1: value1, counter:1}{key1: value1, counter:1}{key1: value1, counter:1, key2: value2}{key1: value1, counter:1, key2: value2}{key1: value1, counter:1, key2: value2}
RDB Filenonenonenonesaved snapshotsaved snapshotsaved snapshotsaved snapshot
AOF Fileempty1 command2 commands2 commands3 commandsrewritten compact filerewritten compact file
Key Moments - 3 Insights
Why doesn't RDB save data after every command?
RDB snapshots happen only at specific triggers (like SAVE command or intervals), not after every command, as shown in steps 1 and 2 where no snapshot occurs.
How does AOF ensure no data loss?
AOF appends every write command immediately, so it logs all changes step-by-step, as seen in steps 1, 2, and 4 where commands are appended.
What happens during AOF rewrite?
AOF rewrite compacts the log by rewriting commands to represent current data state, reducing file size, shown in step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the state of the AOF file after step 2?
AEmpty
B2 commands
C1 command
DRewritten compact file
💡 Hint
Check the 'AOF Action' and 'Resulting State' columns at step 2 in the execution table.
At which step does Redis create a snapshot file?
AStep 1
BStep 4
CStep 3
DStep 5
💡 Hint
Look at the 'RDB Action' column to find when the snapshot is created.
If no new commands come in, what happens next according to the execution table?
ARedis waits for next commands
BAOF file is appended
CRedis creates a new snapshot
DAOF file is rewritten
💡 Hint
See the last row in the execution table under 'Resulting State'.
Concept Snapshot
RDB saves full data snapshots at intervals or commands like SAVE.
AOF logs every write command immediately for durability.
RDB is faster but may lose recent changes.
AOF is slower but safer for data recovery.
Redis can use both for balance between speed and safety.
Full Transcript
This visual execution compares Redis's two data persistence methods: RDB and AOF. When Redis runs, data changes happen by commands like SET or INCR. RDB snapshots save the entire data to disk only at certain triggers, such as the SAVE command, shown at step 3. AOF appends every write command to a log file immediately, ensuring all changes are recorded, as seen in steps 1, 2, and 4. The AOF file can be rewritten to compact it, shown at step 5. If no new commands come, Redis waits for more input. This comparison helps understand how Redis balances speed and data safety using these two methods.

Practice

(1/5)
1. Which Redis persistence method saves the entire dataset at specific time intervals?
easy
A. AOF (Append Only File)
B. RDB (Redis Database snapshot)
C. Both RDB and AOF save snapshots
D. Neither RDB nor AOF save snapshots

Solution

  1. Step 1: Understand RDB persistence

    RDB saves the dataset by creating snapshots at set intervals.
  2. Step 2: Compare with AOF

    AOF logs every write operation, not snapshots.
  3. Final Answer:

    RDB (Redis Database snapshot) -> Option B
  4. Quick Check:

    Snapshot saving = RDB [OK]
Hint: RDB = snapshots at intervals, AOF = logs every change [OK]
Common Mistakes:
  • Confusing AOF with snapshot saving
  • Thinking both save snapshots
  • Believing neither saves snapshots
2. Which of the following is the correct Redis command to enable AOF persistence?
easy
A. CONFIG SET appendonly yes
B. CONFIG SET save "900 1 300 10 60 10000"
C. CONFIG SET rdbcompression no
D. CONFIG SET maxmemory-policy allkeys-lru

Solution

  1. Step 1: Identify AOF enabling command

    The command to enable AOF is CONFIG SET appendonly yes.
  2. 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.
  3. Final Answer:

    CONFIG SET appendonly yes -> Option A
  4. Quick Check:

    Enable AOF = appendonly yes [OK]
Hint: Enable AOF with 'appendonly yes' command [OK]
Common Mistakes:
  • Confusing RDB save command with AOF
  • Using unrelated config commands
  • Forgetting to set appendonly to yes
3. Given Redis configured with AOF enabled and fsync set to 'everysec', what is the expected data durability behavior?
medium
A. Data is saved only at intervals, risking data loss of last seconds
B. Every write is immediately saved to disk, no data loss
C. Data is never saved to disk automatically
D. Data is saved only when Redis restarts

Solution

  1. Step 1: Understand AOF with fsync everysec

    With fsync set to 'everysec', Redis writes AOF data to disk every second.
  2. Step 2: Analyze durability implications

    This means data could be lost if Redis crashes within the last second before fsync.
  3. Final Answer:

    Data is saved only at intervals, risking data loss of last seconds -> Option A
  4. Quick Check:

    AOF everysec fsync = possible 1-second data loss [OK]
Hint: AOF everysec fsync means possible 1-second data loss [OK]
Common Mistakes:
  • Assuming every write is immediately saved
  • Thinking data is never saved automatically
  • Confusing with no persistence
4. You enabled both RDB and AOF persistence in Redis, but after a crash, data is missing. What is the most likely cause?
medium
A. Redis does not support using both RDB and AOF together
B. Redis was not restarted after enabling persistence
C. RDB snapshot interval is too long, losing recent changes
D. AOF file is corrupted and Redis cannot load it

Solution

  1. Step 1: Understand RDB and AOF coexistence

    Redis supports both RDB and AOF, preferring to load AOF first on restart if available.
  2. 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.
  3. Final Answer:

    AOF file is corrupted and Redis cannot load it -> Option D
  4. Quick Check:

    Data loss with both = AOF corrupted [OK]
Hint: With both enabled, data loss likely from AOF corruption [OK]
Common Mistakes:
  • Believing Redis can't use both persistences
  • Thinking RDB interval too long is the cause
  • Forgetting to restart Redis
5. You want Redis to recover data quickly after a crash but can tolerate losing up to 1 minute of recent writes. Which persistence setup is best?
hard
A. Enable AOF with fsync always, disable RDB
B. Enable both RDB and AOF with fsync everysec
C. Enable RDB snapshots every 60 seconds, disable AOF
D. Disable both RDB and AOF for fastest performance

Solution

  1. 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.
  2. Step 2: Compare with AOF options

    AOF with fsync always is slower but safer; both enabled adds overhead; disabling persistence risks total data loss.
  3. Final Answer:

    Enable RDB snapshots every 60 seconds, disable AOF -> Option C
  4. Quick Check:

    Fast recovery + 1 min loss = RDB every 60s [OK]
Hint: RDB snapshots match fast recovery with some data loss [OK]
Common Mistakes:
  • Choosing AOF for fast recovery despite slower startup
  • Enabling both causing unnecessary overhead
  • Disabling persistence risking total data loss
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard