0
0
Redisquery~10 mins

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

Choose your learning style9 modes available
Concept Flow - RDB vs AOF comparison
Start Redis Server
Data Changes Occur
RDB Snapshot Triggered?
YesSave Data Snapshot to Disk
Wait for Next Trigger
AOF Append Command?
YesAppend 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.