How does AOF rewrite work and how does it compare to RDB performance?
Answer
The AOF (Append-Only File) grows indefinitely as every write command is appended. AOF rewrite compacts it by writing the minimal set of current commands that reproduces the current dataset, discarding superseded commands. It runs in a background fork: the child process writes a new, compact AOF from the current in-memory dataset while the parent continues serving commands and buffers new writes. When the child finishes, the buffer is appended and the new file atomically replaces the old one — zero downtime. Configured via auto-aof-rewrite-min-size and auto-aof-rewrite-percentage. Compared to RDB: RDB produces a compact binary snapshot and restarts are fast (load the snapshot). AOF restores by replaying commands — much slower on large datasets. However, AOF with appendfsync everysec loses at most 1 second of data on crash, while RDB can lose minutes. The hybrid RDB+AOF persistence format (Redis 4+) starts AOF restoration from an embedded RDB snapshot, combining fast load with durable logging.
Previous
What is memory optimization in Redis (ziplist, listpack, and encoding thresholds)?
Next
What are Redis Functions (replacing Lua scripts in Redis 7+)?
More Redis Questions
View all →- Advanced How does Redis Cluster sharding and the hash slot algorithm work in detail?
- Advanced What is consistent hashing and how does it compare to Redis Cluster's approach?
- Advanced What is memory optimization in Redis (ziplist, listpack, and encoding thresholds)?
- Advanced What are Redis Functions (replacing Lua scripts in Redis 7+)?
- Advanced What is Redis Stack and what does it add to vanilla Redis?