ACID Properties: Making Databases Reliable


When working with databases, maintaining data integrity and reliability isn’t just important—it’s essential. Imagine a banking system where money disappears mid-transfer or an e-commerce platform that double-charges customers. Chaos, right? This is where ACID properties step in as the unsung heroes, ensuring every transaction is executed safely, consistently, and without errors.
What are ACID properties?
ACID stands for Atomicity, Consistency, Isolation, and Durability.
1. Atomicity
Example:
Transferring $100 from Alice to Bob. This transaction involves 2 operations.Deduct $100 from the Alice's account
Add $100 to the Bob's account
If the system crashes after deducting money from Alice’s account but before adding it to Bob’s account, Atomicity ensures that the entire transaction is rolled back, preventing data inconsistencies.
Atomicity ensures that the whole transaction is treated as a single unit
. Means either all the operations in a transaction will execute successfully, or none of them will. Partial updates are not allowed.
2. Consistency
Example:
Suppose before the transactionAlice has $500
Bob has $300
If Alice transfers $100 to Bob, the new balances should be:Alice: $400
Bob: $400
The total money in the system before the transaction was $500 + $300 = $800
After the transaction, it remains $400 + $400 = $800
Consistency makes sure the database is correct before and after a transaction. It means every transaction follows the rules and keeps the data accurate. If a system error occurs mid-transaction, the rollback mechanism ensures no money is lost or created incorrectly.
3. Isolation
Example:
Suppose John's account balance is $1000
Without IsolationTransaction A:
reads John's balance as $1,000.Transaction B:
adds $500, updating the balance to $1,500.Transaction A:
unaware of Transaction B, deducts $300 from the old balance $1,000 (instead of actual balance $1,500). This sets the balance to $700 instead of the correct $1,200.
With Proper Isolation (Correct Execution)Transaction A:
reads John's balance as $1,000. Temporarily locking the balance from other transactions.Transaction B:
try to add $500 but must wait until Transaction A completes.Transaction A:
deducts $300, current balance is $700. Transaction A commits.Transaction B:
reads the correct balance as $700. Add $500, resulting in the correct final balance of $1,200.
Isolation ensures that concurrent transactions do not interfere with each other. This prevents conflicts and ensures that the execution of multiple transactions produces the same result as if they were executed sequentially.
4. Durability
Durability ensures that once a transaction is successfully committed, its changes are permanently stored in the database, even in case of system crashes, power failures, or unexpected shutdowns. This means that committed transactions cannot be lost—the database guarantees their persistence.
Why Are ACID Properties Important?
Reliability: Ensures that transactions are executed completely or not at all.
Data Integrity: Prevents data corruption and ensures correctness.
Concurrency Control: Manages multiple transactions effectively.
System Recovery: Protects data against crashes and failures.
I hope this post helped you understand the concept better! Thanks for reading. Follow me for more such content.
Subscribe to my newsletter
Read articles from Fahim Ahsan Khan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
