How to Explain Redis Persistence Mechanisms in an Interview
The article walks through Redis’s two persistence options—RDB snapshots and AOF logs—detailing how each works, their advantages and drawbacks, and why interviewees should understand their differences, including AOF rewrite compression, to answer interview questions accurately.
In a mock interview, the interviewer asks which cache technology the candidate uses and then probes the persistence mechanism of Redis, prompting the candidate to explain the difference between RDB and AOF.
Redis persists data to disk in two formats: RDB (Redis DataBase) snapshots and AOF (Append‑Only File) logs. Both allow recovery after a power loss, but they work differently.
RDB – Snapshot
Redis forks a child process at configured intervals, writes the in‑memory dataset to a temporary file, and then atomically replaces the old dump.rdb file. The snapshot captures the state at a specific moment (e.g., 14:00), so any changes after that moment are not included.
Advantages:
The entire database is stored in a single dump.rdb file, simplifying backup.
Good disaster‑recovery characteristics.
High performance because the child process handles I/O while the main process continues serving commands.
Faster startup for large datasets compared with AOF.
Disadvantages:
Potential data loss between snapshots; not suitable for scenarios requiring strict durability.
Forking a large dataset may pause the server for hundreds of milliseconds or even a second.
AOF – Append‑Only Log
Every write or delete command (e.g., set name 小帅, set name 小美, set name 佛波勒) is appended to an AOF file. During recovery, Redis replays the logged commands in order, reconstructing the final state.
Because the log records every operation, the file can grow large. Redis mitigates this with an automatic Rewrite process: when the AOF reaches a configured size (e.g., 64 MB), Redis rewrites a compacted version that contains only the minimal set of commands needed to recreate the current dataset.
Advantages:
Higher data safety; three sync policies (every second, every write, or no sync) let users trade latency for durability.
Append‑only writes survive crashes without corrupting existing data; redis-check-aof can fix inconsistencies.
The rewrite mechanism periodically compresses the file.
Disadvantages:
The AOF file is larger than an RDB snapshot and recovery is slower.
For large datasets, startup time is slower than RDB.
Overall runtime performance is lower than RDB.
In summary, interviewers expect candidates to know that RDB offers fast snapshots with possible data loss, while AOF provides stronger durability at the cost of larger files and slower recovery, and that Redis mitigates AOF growth through rewrite compression.
Architect's Journey
E‑commerce, SaaS, AI architect; DDD enthusiast; SKILL enthusiast
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
