Skip to content
AOF — Append-Only File Logging
step 1/3

Reading — step 1 of 3

Append-Only File

~1 min readAdvanced Features

AOF — Append-Only File Logging

AOF is Redis's second persistence mechanism. Instead of snapshotting all data, it logs every write command.

How It Works

  1. Every write command (SET, DEL, LPUSH, etc.) is appended to a log
  2. On restart, Redis replays the entire log to rebuild state
  3. The log only grows — periodic "rewrite" compacts it

RDB vs AOF

FeatureRDBAOF
Data loss windowMinutes (between saves)Seconds (fsync policy)
File sizeCompactLarger (every command)
Restore speedVery fastSlower (replays commands)
CPU costHigh (serialization)Low (just append)

Real Redis Recommendation

Use both: RDB for fast restarts + AOF for minimal data loss. Redis can even rewrite the AOF in the background.

What You'll Build

  • AOF ON/OFF — toggle logging
  • AOF DUMP — view the command log
  • AOF REPLAY — rebuild state from the log
  • Only write commands are logged (not GET, LRANGE, etc.)

This teaches the fundamental concept behind write-ahead logging — used in every serious database.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…

AOF — Append-Only File Logging — Build Redis from Scratch