Why Batching is Inevitable
Syscall overhead + block I/O make batching a physics requirement, not a choice.
Writing 64 KiB with different batch sizes. Cost = syscall overhead + I/O latency.
The 1-byte-at-a-time nightmare
Writing 64 KiB one byte at a time = 65,536 syscalls. Each syscall crosses the user/kernel boundary — even on a fast machine, that's 328 ms of pure overhead, before any disk I/O.
Cost model
Simplified model. Real syscall overhead varies 1–20μs. SSD latency ~50–200μs. HDDs 5–15ms.
Rust BufWriter
Key Insight
Batching isn't an optimization — it's physics. Two facts make it inevitable:
- Every syscall has ~5μs overhead (kernel mode switch). 1000 × 1-byte writes = 5ms of overhead alone.
- Every disk operation transfers at least 4 KiB. Writing 100 bytes in 100 separate syscalls still does 100 disk ops.
This is why SST files use 4 KiB blocks. It's not a design preference. You're paying for a 4 KiB block transfer whether your data is 1 byte or 4096. Fill the block. And it's why the MemTable exists — batch all writes in RAM until you have enough to justify flushing to disk.
Now you have all the primitives. Let's build something real with them: a write-ahead log from scratch.