Redis & Caching (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
How does AOF Rewrite (BGREWRITEAOF) prevent infinite log file growth?
senior LevelSystem Design
In Simple Words:
If a key is updated 10,000 times (INCR counter), the AOF file contains 10,000 lines:
- AOF Rewrite: Redis forks a child process to inspect the current state of memory and writes the minimum necessary commands to recreate the dataset in a new file (replaces 10,000
INCRlines with one singleSET counter 10000!). - Swaps the new compact AOF file atomically.