What are ACID Properties in Databases?
ACID stands for:
| Letter | Property | Meaning |
|---|---|---|
| A | Atomicity | All or nothing — a transaction is fully done or fully undone. |
| C | Consistency | The database moves from one valid state to another. |
| I | Isolation | Transactions do not interfere with each other. |
| D | Durability | Once committed, the transaction’s changes are permanent. |
Let’s Break Each One Down
1. Atomicity (A) — “All or Nothing”
A transaction must be fully completed or fully rolled back.
- If any part of the transaction fails, the whole transaction fails.
- The database won’t be left in a half-updated state.
✅ Example:
- You transfer money:
- Debit from one account.
- Credit to another.
- If the debit succeeds but the credit fails — rollback the debit — no partial transfer.
2. Consistency (C) — “Valid State”
A transaction must maintain database rules.
- After the transaction, the database must be in a consistent state.
- All constraints, triggers, foreign keys, business rules must be respected.
✅ Example:
- Balance cannot go negative (business rule).
- Foreign key constraints must not be violated.
If a transaction violates a rule — it fails and is rolled back.
3. Isolation (I) — “Transactions Don’t Bump Into Each Other”
Each transaction is independent of other concurrent transactions.
- Intermediate results are hidden from other transactions.
- No “dirty reads,” “phantom reads,” or “non-repeatable reads” — depending on isolation level.
✅ Example:
- Two users booking the last ticket simultaneously:
- Only one can succeed.
- They shouldn’t see inconsistent intermediate states.
Databases provide isolation levels: Read Uncommitted, Read Committed, Repeatable Read, Serializable.
4. Durability (D) — “It’s Permanent”
Once a transaction is committed, it is permanently recorded, even if:
- There is a crash.
- A power failure occurs.
- Changes are stored in non-volatile storage (disk, SSD).
- Databases often use Write-Ahead Logs (WALs) to ensure durability.
✅ Example:
- After you book a ticket and get confirmation, it’s safe — even if the server crashes the next second.
In Short
| ACID | Guarantee |
|---|---|
| Atomicity | All steps succeed or none at all. |
| Consistency | Database rules are not violated. |
| Isolation | Transactions don’t interfere with each other. |
| Durability | Committed transactions survive failures/crashes. |
Why is ACID Important?
- It ensures that databases are reliable, even with:
- System crashes
- Power failures
- Multiple concurrent users
- Without ACID:
- Money could be lost in transit.
- Seats could be double-booked.
- Inventory could become negative.
✅ ACID protects your data and makes databases trustworthy.
Real-Life Analogy
Bank Transaction:
- Atomicity: Transfer all money or none.
- Consistency: Balances must still add up correctly.
- Isolation: Your transfer doesn’t collide with someone else’s at the same time.
- Durability: Once you get confirmation, the transfer is safe forever.