Removing fsync from our local storage engine
TL;DR Highlight
Preallocation, O_DIRECT and 4KB atomic journal commits drop fsync, giving 1.6x write throughput
Who Should Read
Backend or infrastructure developers building S3-compatible object stores or KV engines who are struggling with write latency and tail latency
Core Mechanics
- fsync costs more than it looks
- A single fsync on an SSD typically takes a few hundred microseconds to a couple of milliseconds.
- It also flushes inode, extent map and filesystem journal commits, so I/O can grow several times over.
- Preallocate files and zero them up front
- fallocate fixes journal and data area sizes at startup, so file size never changes on writes.
- fallocate alone leaves unwritten extents that need a metadata update on first write, so they zero the whole region once (pre-zeroing).
- Journal commits are 4KB atomic blocks
- It relies on a device contract that a 4KB-aligned commit block cannot tear on power loss.
- Power loss can only land between commit blocks, never inside one.
- Recovery uses checksums and sequence numbers
- Each commit block carries a checkpoint epoch, an increasing sequence number and a checksum.
- On restart it loads the newest checkpoint and replays the journal while checks pass.
- The PUT path has zero fsync calls
- Allocate space, write the value with O_DIRECT, write a 4KB journal commit, then update the in-memory index.
- If power fails after the value write but before the commit, the space-map scan marks it uncommitted and invisible.
- The scope is very narrow
- It assumes SSD only: cloud local NVMe or enterprise NVMe with protected cache.
- If the contract does not hold, reject no-fsync mode or use a sync-based journal path.
Community Reactions
- The benchmark measures the local write path only
- AWS i8g.2xlarge local NVMe, 4KB random writes, io_uring QD=100.
- Throughput is 190,985 obj/s, 1.6x ext4+O_DIRECT+fsync at 116,041 and 2.4x ext4+buffered+fsync at 79,123.
- Average latency is 413µs, 2.1x and 3.1x lower, with P99 at 1013µs versus 1425µs and 1852µs.
- The baselines were given an easier job
- Both ext4+fsync configs only fsync the data file, not the parent directory.
- The article says adding the directory fsync would only make their latency worse.
- Many commenters pushed back that the ACK cannot be trusted because of disk caches
- Several said O_DIRECT only skips the page cache and does not guarantee a drive cache flush.
- One said you cannot prove bytes reached disk without fsync, so ACKed writes may not survive a failure.
- The author replied that the design depends on SSD-only deployment, preallocated files, O_DIRECT, single-key atomicity and device write guarantees, and is not a general argument against fsync.
- Commenters raised WAL ordering and O_DSYNC
- One said SSDs may reorder writes internally, so a later WAL block could survive while an earlier one is lost, leaving a hole in the log.
- Another said adding O_DSYNC to O_DIRECT is more correct because it adds FUA when the disk needs it.
- Reactions to the open-source status
- One commenter said the repo only contains an API gateway and the storage engine itself is not open sourced.
- The author of a similar S3-compatible project, hs5, said they use fsync by default, believe defaults should always fsync, and use a checksummed, sequence-numbered WAL.
How to Apply
- Count the fsync calls on your write path
- Grep your PUT and DELETE handlers for fsync and fdatasync today.
- List in a table whether each syncs file data, the parent directory or a metadata file.
- Benchmark O_DIRECT against fsync yourself
- Run 4KB random writes with fio on local NVMe, comparing buffered+fsync and O_DIRECT+fsync.
- Record average and P99 latency separately.
- Fix file sizes and pre-zero them
- For log or data files, run fallocate at startup, write zeros across the whole region, and never change the size at runtime.
- Check that the latency spikes on first writes disappear.
- Verify the device contract before dropping fsync
- Confirm the target disk is local NVMe or NVMe with protected cache, and read its atomic write unit values.
- Keep the sync-based path in any environment you cannot confirm.
Try It
# Paste into Claude or ChatGPT as-is (simplified version of the article's method: design review prompt)
Review whether fsync can be removed from the storage design below.
[Design]
- Journal and data areas are preallocated at fixed size with fallocate, then pre-zeroed
- All writes use O_DIRECT with aligned buffers
- Journal commits are 4KB-aligned blocks with checkpoint epoch + sequence number + checksum
- Recovery: load newest checkpoint, replay journal while checksum and sequence checks pass
[Our environment]
- Disk: {{disk type/model}}
- Value size: {{value size range}}
- Durability requirement: {{e.g. ACKed data survives power loss}}
Answer in a table:
1. Device guarantees this design depends on
2. Assumptions that could break in our environment
3. How to verify them (include commands)
4. Sync-based alternatives if assumptions failTerminology
Related Papers
A Beginner's Guide to Local AI with Inkling, Qwen, and Unsloth
Install Unsloth Desktop, load a quantized Qwen model, and share a private ChatGPT-like AI on your home LAN.
Muru – AI-assisted Rust server for Python apps by mod_WSGI's creator
mod_wsgi's creator is building Muru, an AI-assisted Rust ASGI/WSGI server, documenting it in public
87% of the Anthropic power will come from gas and 11% from coal in 2028
Analysis of Anthropic's contracted data centers: 87% gas, 11% coal power in 2028
Anthropic’s Nasdaq debut
Anthropic listed on Nasdaq and closed its first day below its opening price.
OpenAI still has a WebRTC Problem
WebRTC drops late audio, hurting voice AI; MoQ retransmits and buffers instead
Gemini 4 Neon
Gemini 4 Neon cuts cost per task 32% versus Carbon, at $3 input and $15 output per million tokens
AI is killing All About Berlin
After Google AI Overviews, a Berlin guide site lost 70-75% of its traffic.
Not Everything Needs an LLM
PostHog used small decision models to skip 98.7% of expensive LLM calls