Your Database Is Making 4 Promises. Here's What ACID Means.
Introduction Your program keeps opening transactions. A signup writes a new user row. A checkout debits one account and credits another. A form submission updates three related tables at once. You wrap it all in BEGIN and COMMIT and move on, trusting that the database will handle whatever happens in between. Most of the time it does. But what is it actually promising you when it handles that? And…
Your program often runs multiple database operations within a single transaction. This is common for things like signing up a user, processing a purchase, or updating several related tables simultaneously. You wrap all these operations inside a BEGIN and COMMIT pair, trusting the database to handle everything safely in between. Most of the time, it manages this perfectly.
But sometimes, a crash can interrupt a transaction mid-way. Consider a user transferring ₹1,000 from Account A to Account B. The database runs two updates - subtract ₹1,000 from Account A and add ₹1,000 to Account B. If the server crashes right after the first update, Account A ends up with a debit of -₹1,000 while Account B shows no change.
The money never moved, and there's no error message to explain this. This demonstrates the exact problem ACID was designed to solve. ACID stands for Atomicity, Consistency, Isolation, Durability - four guarantees the system ensures for any transaction. Atomicity is the most fundamental promise. It guarantees that all parts of a transaction happen together as one indivisible unit.
If any part fails, the entire transaction is rolled back, leaving no partial results. So in the transfer example, if the second update fails, both updates are undone, ensuring the user's balance doesn't disappear unexpectedly. Atomicity prevents the unreliable situation where a transaction leaves behind an incomplete state that other transactions can observe.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.