Cianplan

Level 0: Orientation & prerequisites · L0.2 OS & hardware basics for architects

Durability: when is data really saved?

Explain page cache, fsync and why write() is not durability.

12 min · Free

What you take away

  • write() copies into the OS page cache and returns; the data is in volatile RAM, not on the drive.
  • fsync() is the call that asks for it to be on stable media, and it costs ~0.5–2 ms even on NVMe.
  • Databases fsync a write-ahead log, not the data files, and batch many commits into one fsync (group commit).
  • Durability is a choice with a price: buffering is fast and loses recent writes; fsync-per-commit is safe and caps a single writer at a few hundred commits per second.

How the class is laid out

  1. The problem
  2. The simple version
  3. The layers between your code and the platter
  4. What that costs, and what databases do about it
  5. Memory hierarchy
  6. Processes and threads
  7. Async I/O
  8. Durability
  9. Check your understanding