Redis appendfsync Explained: Balancing Performance and Data Durability
Introduction
The appendfsync directive controls how often Redis synchronizes the Append Only File (AOF) to disk.
When AOF persistence is enabled, every write operation is appended to the AOF buffer. The appendfsync setting determines when those buffered writes are flushed to permanent storage.
Choosing the correct synchronization policy is important because it directly affects write performance, disk I/O, and the amount of data that could be lost after an unexpected crash.
This guide explains how appendfsync works, the available synchronization policies, and recommended settings for production environments.
Default Value
The default Redis configuration is:
appendfsync everysec
This provides a good balance between durability and performance.
Syntax
appendfsync always
appendfsync everysec
appendfsync no
How appendfsync Works
When AOF is enabled:
Redis executes a write command.
The command is appended to the AOF buffer.
Redis writes the buffered data to the AOF file according to the appendfsync policy.
If Redis restarts, the AOF file is replayed to rebuild the dataset.
The synchronization policy determines when the operating system flushes the AOF file to disk.
Available Policies
always
appendfsync always
Redis synchronizes the AOF file after every write operation.
Advantages
Maximum durability.
Minimal data loss.
Suitable for critical workloads.
Disadvantages
Highest disk I/O.
Slowest write performance.
everysec
appendfsync everysec
Redis synchronizes the AOF file approximately once every second.
Advantages
Excellent balance between durability and performance.
Recommended for most production deployments.
Usually limits potential data loss to about one second.
Disadvantages
A small amount of recent data may be lost during a crash.
no
appendfsync no
Redis leaves synchronization entirely to the operating system.
Advantages
Highest write performance.
Lowest synchronization overhead.
Disadvantages
Greater risk of data loss during unexpected shutdowns.
Flush timing depends on the operating system.
Policy Comparison
Configure appendfsync
Open the Redis configuration file.
sudo nano /etc/redis.conf
Example:
appendonly yes
appendfsync everysec
Restart Redis.
sudo systemctl restart redis
Verify the Configuration
Run:
redis-cli CONFIG GET appendfsync
Example output:
1) "appendfsync"
2) "everysec"
Change the Setting Without Restarting
redis-cli CONFIG SET appendfsync always
Remember to update redis.conf if the change should remain after a restart.
Choosing the Right Policy
There is no universal choice. The best setting depends on how much data loss your application can tolerate.
Common Mistakes
Using always for High-Write Workloads
While always offers the strongest durability, it can significantly reduce throughput on busy servers because every write must be synchronized to disk.
Assuming no Disables AOF
The no policy does not disable AOF persistence. It only delegates disk synchronization to the operating system.
Ignoring Hardware Performance
The effectiveness of each policy depends on storage hardware. SSDs generally provide much better synchronization performance than traditional hard drives.
Best Practices
Enable AOF only when persistence is required.
Use appendfsync everysec for most production systems.
Choose always only when maximum durability outweighs performance.
Monitor disk latency and AOF performance regularly.
Combine AOF with RDB snapshots for improved recovery options.
Related Articles
Conclusion
The appendfsync directive controls how frequently Redis synchronizes AOF data to disk, making it one of the most important settings for balancing performance and durability.
For most production environments, appendfsync everysec is the recommended choice because it offers excellent write performance while limiting potential data loss to approximately one second. Applications with stricter durability requirements may choose always, while cache-only deployments often benefit from the higher performance of no.
Explore More
› Redis Persistence Explained: RDB vs AOF and Data Durability
› Redis save Explained: Configuring RDB Snapshots for Data Persistence
› Redis Explained: In-Memory Data Store, Persistence, and Best Practices
› Redis maxmemory Explained: How to Limit Memory Usage and Prevent OOM Errors
› Why Do People in Southeast Asia Love Iced Drinks? The Climate, Culture, and Science Explained
› Northern vs Southern Chinese Business Culture: Key Differences Explained