Durability: Surviving System Failures
What you'll learn: How databases guarantee that once a transaction commits, your data survives crashes, power failures, and system restarts.
The Durability Promise
Durability is the "D" in ACID properties, and it's all about permanence. When a database confirms your transaction committed successfully, that data must survive any subsequent failure—even if the server crashes one millisecond later. No exceptions.
Think of durability like a receipt at a store. Once the cashier hands you that receipt, the store can't pretend your purchase never happened, even if their computer crashes immediately after. The transaction is permanent.
How Databases Achieve Durability
Databases use two key mechanisms:
Write-Ahead Logging (WAL): Before modifying any data in memory or on disk, the database first writes the change to a sequential log file. This log is written to disk and flushed (forced to physical storage) before confirming the commit. Even if the system crashes before updating the actual data files, the database can replay the log on restart to recover committed transactions.
Disk Writes: After logging, changes are eventually written to the actual data files on disk. This happens asynchronously for performance, but the log ensures nothing is lost. If a crash occurs mid-write, the log tells the database what was committed and what wasn't.
Why It Matters
Without durability, every system crash would mean lost orders, missing payments, or corrupted account balances. Durability is why you trust that your bank balance won't randomly reset, even if their servers reboot.
Key Takeaway: Durability ensures committed transactions survive any failure through write-ahead logging that forces changes to persistent storage before acknowledging success, making your data permanent and crash-proof.