Databases 11 min read

Mastering Redis Persistence: RDB Snapshots and AOF Explained

This article explains why Redis data must be persisted, compares the two built‑in methods—RDB snapshotting and Append‑Only File (AOF)—and provides practical configuration tips, command usage, performance considerations, and verification tools for reliable backup and recovery.

Java Backend Technology
Java Backend Technology
Java Backend Technology
Mastering Redis Persistence: RDB Snapshots and AOF Explained

Introduction

Redis stores data in memory, which offers high performance but risks data loss during power failures or crashes. To ensure reliability, Redis provides two persistence mechanisms that write data to non‑volatile storage, allowing recovery after restarts or failures.

Snapshot Persistence (RDB)

RDB creates point‑in‑time snapshots of the dataset. The BGSAVE command forks a child process that writes the snapshot to disk while the parent continues serving requests. SAVE performs the same operation synchronously, blocking all clients until the snapshot is finished.

Snapshots are triggered automatically based on save configuration lines (e.g., save 60 1000 means create a snapshot if 1000 writes occur within 60 seconds). Multiple save rules can be defined, and any rule that matches will start a snapshot.

Snapshots are fast for small datasets but can cause noticeable pauses on large datasets because the forked child must copy memory. Administrators often schedule snapshots during low‑traffic periods or use manual BGSAVE / SAVE to control timing.

When memory usage is high, the fork operation may stall the server; disabling automatic saves and using manual commands can mitigate this.

AOF Persistence

AOF logs every write command to an append‑only file. On restart, Redis replays the file to reconstruct the dataset.

To enable AOF, set appendonly yes. The appendfsync option controls how often the file is flushed to disk:

always : flush after every write (high durability, low performance).

everysec : flush once per second (balanced).

no : let the OS decide (best performance, risk of data loss).

Large AOF files can be rewritten to a compact form with BGREWRITEAOF, which creates a child process that removes redundant commands. Automatic rewriting is controlled by auto-aof-rewrite-percentage and auto-aof-rewrite-min-size (e.g., rewrite when the file exceeds 64 MB and has grown by 100%).

Verifying Snapshot and AOF Files

Redis provides redis-check-aof and redis-check-dump utilities to inspect and repair RDB and AOF files. Using the --fix flag on redis-check-aof truncates the file at the first corrupted command, preserving all earlier valid commands.

Conclusion

Both RDB snapshots and AOF logging offer reliable persistence for Redis. Choose RDB for infrequent writes or when fast restarts are needed, and AOF for maximum durability. In production, many deployments combine both methods and regularly back up the generated files to secondary servers.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

databaseredisPersistenceBackupAOFRDB
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.