BeCuriouzBeCuriouz

Learn something new every day

✍️ Blogs
💾

Saving a file sounds trivial — engineers say it's terrifyingly hard

💡 Writing a file correctly means surviving a crash at any instant — and most software quietly gets this wrong.

In his widely-read post "Files Are Hard," engineer Dan Luu dismantles one of computing's most comforting illusions: that when your program "saves" a file, the data is safely on disk. In reality, a write travels through layers of application buffers, operating-system caches, and drive caches before it truly lands. A crash or power loss at any point can leave you with a half-written file — or, worse, a file that looks fine but is silently corrupt.

The uncomfortable punchline is that this isn't a rare edge case. When researchers tested widely-used applications — including databases and version-control tools that people trust with critical data — many mishandled crashes and lost or corrupted data. The correct incantations (like calling fsync on both the file and its parent directory, in the right order) are subtle, poorly documented, and behave differently across filesystems.

The deeper lesson for beginners: durability is not free. "It's saved" is a promise the whole stack has to keep together, and each layer optimizes for speed by lying a little about when data is really persisted. Great engineering blogs like Luu's exist to expose exactly these hidden assumptions — the boring-sounding operations that turn out to hide enormous complexity.

📚

Source: Files Are Hard

💾 Saving a file sounds trivial — engineers say it's terrifyingly hard — BeCuriouz