"Saving" is Complicated
When you write a simple Python script that saves text to a file (f.write("Hello")), you trigger a chain reaction deep inside the operating system. Most developers treat storage as a black box: you put data in, and it stays there. But understanding the layers between your code and the physical disk is what separates a junior developer from a database architect — and it is exactly the kind of knowledge that surfaces in SRE and platform engineering interviews.
This journey passes through several distinct layers, each with its own responsibilities and failure modes:
- VFS (Virtual Filesystem): A common interface that lets the kernel talk to any filesystem using the same API, whether it is ext4, XFS, or a network filesystem like NFS.
- Page Cache: A RAM-based staging area where data lives before it is committed to disk.
- Filesystem (ext4, XFS, Btrfs): The organizer that manages inodes, directory trees, and free space.
- Block Layer: The traffic controller that translates file-level requests into sector-level requests and optimizes their ordering.
- Device Driver: The translator that speaks the hardware's native language (SATA, NVMe, SCSI).
- Physical Hardware: The actual spinning platter or NAND flash that stores bits.
Each layer adds latency, but also adds value. Removing a layer (as databases do with Direct I/O) trades safety and convenience for performance and control.