Quick revision
The short answer
The log line means the background fsync of the AOF did not finish within two seconds, so the disk is stalling and dragging the single Redis main thread with it: writes to the AOF block behind the slow fsync, and every client waits. The fix starts with the disk, a dedicated volume with enough provisioned IOPS and throughput and fewer rewrites, then no-appendfsync-on-rewrite where some extra loss is acceptable, and finally moving durability off this node if it does not need it.
What to remember
In this answer, we connected the log line to the spikes. A slow disk makes the background fsync last for seconds, Redis postpones writes for up to two seconds and then writes anyway, and that write blocks the single main thread, so every client waits. We found the usual causes, a disk shared with logs, rewrites and saves in a child, and burst-limited cloud volumes, and confirmed them with iostat and the latency monitor. The fixes, in order, are a dedicated well-provisioned disk with fewer rewrites, no-appendfsync-on-rewrite where extra loss is acceptable, and keeping durability off this primary if it does not need it.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The log line means the background fsync of the AOF did not finish within two seconds, so the disk is stalling and dragging the single Redis main thread with it: writes to the AOF block behind the slow fsync, and every client waits. The fix starts with the disk, a dedicated volume with enough provisioned IOPS and throughput and fewer rewrites, then no-appendfsync-on-rewrite where some extra loss is acceptable, and finally moving durability off this node if it does not need it.
Why this question is asked
A latency spike that appears every few minutes, on a server whose CPU looks idle, is a classic sign that something below Redis is slow. Interviewers like this question because it tests whether we know that Redis is single-threaded for commands, so anything that blocks the main thread, even for a moment, blocks every client. In this answer, we will recap how everysec uses the disk, connect the log line to the spikes step by step, find what is stalling the disk, confirm it with the tools Redis gives us, and then go through the fixes in order of preference.
1A Quick Recap of How everysec Touches the Disk
With appendfsync everysec, two threads use the AOF file. The main thread, which executes every command for every client, calls write() on each event loop cycle to copy new commands into the operating system's page cache. A background thread calls fsync() about once a second to force those pages to the physical disk.
Normally the main thread never waits for the disk, because write() into the page cache is a memory copy. The trouble starts when fsync is slow. On Linux, a write() to a file that is in the middle of a long fsync can block inside the kernel until the fsync makes progress. If the main thread blocks, Redis stops serving everyone.
2How the Log Line and the Spikes Connect
Redis knows about this danger, so before writing it checks whether the background fsync is still running. If it is, Redis postpones the write and keeps the commands in its own buffer, and it can do so for up to two seconds. When two seconds pass and the fsync is still not done, Redis gives up waiting, performs the write anyway and logs the message we see. That write can now block the main thread until the disk catches up.
So the sequence during each spike is: the disk slows down, fsync takes seconds, Redis first postpones writes and then writes into a blocked file, and the main thread stalls. Every command from every client waits behind it, which is why p99 jumps from 1 ms to over a second while CPU stays low. Notice that the log line is a symptom: the disk is stalling the whole server.
7 messages in order. Play them, or step through them one at a time.
While the main thread is blocked, every other client waits too.
3Finding What Stalls the Disk
Here the disk is shared with application logs, which is the first suspect. Log shipping agents and log rotation write in bursts. Redis itself adds load: an AOF rewrite or an RDB save runs in a child process that writes a large file, and that heavy write traffic makes the parent's fsync slow. A further common cause in the cloud is a burst-limited volume, such as a general purpose volume that runs on credits: when the credits run out, IOPS and throughput drop to a low baseline and every fsync slows down.
Notice what each tool tells us. iostat shows whether the device itself is slow, with write wait times measured in milliseconds per request. The Redis latency monitor records events such as aof-write-pending-fsync whenever a write had to wait for an fsync, and aof_delayed_fsync in INFO persistence counts how many times the two-second limit was hit. If those events line up with rewrites or with the volume's IOPS and throughput graphs hitting their limit, we have the cause.
4Fix 1: Fix the Disk
The most effective fix is to give Redis a disk that does not stall. That means its own volume, with logs moved elsewhere, and provisioned IOPS and throughput sized above the peak rate of AOF writes plus the rewrite traffic, rather than a burst-limited volume. This removes the cause instead of hiding it, and it keeps the durability the team chose.
We should also make rewrites rarer and more predictable. auto-aof-rewrite-percentage (100 by default, meaning rewrite when the file has doubled) and auto-aof-rewrite-min-size (64 MB by default) decide when a rewrite starts. Raising the minimum size, for example to a few gigabytes on a busy node, avoids frequent rewrites of a fast-growing file.
5Fix 2: Skip fsync During Rewrites, If Some Loss Is Acceptable
no-appendfsync-on-rewrite yes tells Redis not to fsync while a rewrite or an RDB save is running in a child. That removes the competition between the parent's fsync and the child's large writes, so the spikes during rewrites disappear. The cost is durability: during the rewrite, the AOF behaves like appendfsync no, and a host failure at that moment can lose much more than a second, up to about 30 seconds with default Linux settings.
So this is acceptable for a cache or for data we can rebuild, and not for data that must survive. It is a decision to write down, not a tuning knob to flip quietly.
6Fix 3: Move Durability Off This Node
If this primary does not need durable writes, for example because it holds a cache or because the data is rebuilt from a database, we can turn AOF off on the primary and keep it on a replica, or rely on RDB snapshots only. The primary then never touches the disk on the request path. The trade-off is that a failover or a restart of the primary loses whatever the replica or the last snapshot did not have, which must be acceptable for this data.
| Fix | Removes spikes | Durability cost |
|---|---|---|
| Dedicated volume, provisioned IOPS | yes, at the cause | none |
| Fewer rewrites (min size, percentage) | reduces how often | none |
| no-appendfsync-on-rewrite yes | during rewrites | can lose ~30 s if host fails mid-rewrite |
| AOF on replica only, or RDB only | yes, on the primary | loses what the replica or snapshot lacks |
7Follow-up questions
How would you confirm that the disk, not Redis, is the bottleneck?
I would line up three signals at the spike times. On the host, iostat -x shows write await in hundreds or thousands of milliseconds and utilisation near 100 percent on the AOF volume, and the cloud console shows the volume at its IOPS or throughput limit or out of burst credits. In Redis, LATENCY LATEST shows aof-write-pending-fsync events of the same length as the spikes, and INFO persistence shows aof_delayed_fsync increasing. Meanwhile Redis CPU stays low and SLOWLOG shows no slow commands, so the time is not spent executing anything. If all of that agrees, the disk is the bottleneck.
Why does a slow fsync in another thread block the main thread at all?
Because both threads touch the same file. On Linux, a write() to a file whose pages are being flushed by a long fsync can wait for the flush, so the main thread ends up waiting for the disk even though it never called fsync itself. Redis postpones writes for up to two seconds to avoid this, but after that it must write.
8Conclusion
In this answer, we connected the log line to the spikes. A slow disk makes the background fsync last for seconds, Redis postpones writes for up to two seconds and then writes anyway, and that write blocks the single main thread, so every client waits. We found the usual causes, a disk shared with logs, rewrites and saves in a child, and burst-limited cloud volumes, and confirmed them with iostat and the latency monitor. The fixes, in order, are a dedicated well-provisioned disk with fewer rewrites, no-appendfsync-on-rewrite where extra loss is acceptable, and keeping durability off this primary if it does not need it.
Open with
That log line means the background fsync of the AOF took more than two seconds. With everysec, the main thread writes to the AOF and a background thread fsyncs it.
Then, if they want more
When the fsync is slow, Redis postpones writes for up to two seconds, then writes anyway and logs this message, and that write can block the main thread behind the fsync. Since one thread serves every command, all clients wait, which is the p99 jump from one millisecond to over a second while CPU stays low.
The disk here is shared with application logs, and the usual triggers are log bursts, an AOF rewrite or RDB save in a child process, or a burst-limited cloud volume that ran out of credits.
I would confirm it with iostat await and the volume's IOPS graphs at the spike times, and with LATENCY LATEST showing aof-write-pending-fsync events and aof_delayed_fsync rising in INFO persistence. My first fix is the disk: a dedicated volume with provisioned IOPS and throughput, logs moved off it, and fewer rewrites through auto-aof-rewrite-min-size.
Second, no-appendfsync-on-rewrite yes removes spikes during rewrites but can lose more data if the host dies then, so only for data we can lose. Third, if this node does not need durability, keep AOF on a replica or use RDB only.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Redis documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain the link between this log line and the latency spikes, and give the fixes in...": https://scrivio-interview-library.netlify.app/databases/redis-scaling/303f64a3b7/