![[chap_5_wal.png]] # Chapter 5: Safety & Promises (The Pocket Diary) When an elephant makes a change to a piece of data—crossing out a name, rewriting a phone number, deleting an order—you, the user, demand absolute safety. You demand that if the power goes out the very next second, your change will survive the apocalypse. But walking directly over to the massive, terrifying metal filing cabinet, finding the incredibly specific file folder, and painstakingly changing a single letter in permanent ink... is utterly exhausting. To do that for every single minor change would quickly bring the elephant to tears. So, the elephant cheats. It uses the [[WAL|Write-Ahead Log]]. Instead of sorting the actual files into the cabinet, the panicking elephant simply maintains a frantic, sequential diary on its desk. Every time you ask for a change, the elephant scribbles "At 3:00 PM, I crossed out Sarah's name" wildly into the diary. Writing linearly in a diary is incredibly fast and takes almost zero mental effort. As soon as the ink is dry, the elephant yells "Done!" and gives you a thumbs up. The database is now officially safe. If the power dies, the elephant will simply wake up, read the diary, and re-apply all the scribbled notes. But often, a single change isn't enough. Sometimes you need to make three changes at once, and if any of them fail, you want the elephant to pretend you never walked in the door. For this, the engine uses the [[Transactions|Pinky Swear (Transactions)]]—a guarantee that either everything in your session happens, or nothing happens at all. Eventually, of course, the actual filing cabinet must be updated. But the elephant does this on its own schedule, in the background, out of your sight. When it finally feels like organizing the real data, it will perform a Checkpoint, calmly synchronizing its lazy, chaotic diary with the cold, hard physical reality of the disk.