# 4.1 The Pocket Diary

In the database warehouse, the [[Chapter 1/1.2 - The Page|Filing
Cabinet]] is the ultimate source of truth. But as we've seen, the cabinet is
slow, frozen, and located in a distant basement.
The elephant’s primary trick for survival is the
**[[Architecture/WAL|Write-Ahead Log (WAL)]]**, or the **Pocket
Diary**.
## The Sequential Scribble
When you ask for a change, the elephant doesn't go to the basement. Instead, he
pulls a small, cheap notebook out of his pocket and scribbles exactly what he's
about to do: _"I am going to change Row 5 on Page 42 from 'Blue' to 'Red'."_
Writing in a straight line in a small notebook is incredibly fast. There is no
searching, no heavy iron drawers to pull, and no organization required. It is
just one scribble after another.
## The Handshake (fsync)
But a scribble in a notebook is only safe if the notebook itself is safe. If the
elephant scribbles the note and then the power goes out before the ink is dry,
the note is lost forever.
This is where **`fsync`** comes in.
Think of `fsync` as a **Handshake with the Basement**. The elephant scribbles
his note, then sticks his head down the laundry chute and yells to a worker in
the basement: _"Did you catch that? Is it on the paper?"_
The elephant then **stops everything**. He stands there, heart pounding, waiting
for the basement worker to yell back: _"GOT IT! IT'S ON THE DISK!"_
Only after that shout arrives does the elephant tell you the transaction is
"Committed." This waiting—the `fsync` latency—is the "Safety Tax" you pay for
every change. It is why writing one row at a time is so much slower than writing
a thousand rows in a single session.
## The Checkpoint (Background Cleaning)
Eventually, the Pocket Diary gets full. Every now and then, the elephant must
take a deep breath, gather his courage, and head to the basement to actually
update the Filing Cabinet with all the scribbles he's made. This is a
**Checkpoint**.
While he’s down there, he’s not answering his pager. If the checkpoint is too
heavy, the entire warehouse slows down. But once it’s done, the old pages of the
Pocket Diary can be torn out and recycled.
---
[[Chapter 4/4.0 - Safety Without Sweating|← 4.0 - Safety Without Sweating]] | [[Chapter 4/4.0 - Safety Without Sweating|↑ 4.0 - Safety Without Sweating]] | [[Chapter 4/4.2 - The Recovery Parade|4.2 - The Recovery Parade →]]