ACID Properties
ACID Properties (Explained Simply)
ACID is a set of four properties that help databases execute transactions reliably and correctly, even in tough situations like system crashes or network failures. Together, they make sure your data stays accurate and trustworthy.
A — Atomicity (All or Nothing)
Atomicity means a transaction is treated as one single unit of work:
- If all steps succeed → COMMIT
- If any step fails → ROLLBACK (everything is undone)
Example: Transferring money from Account A to Account B should either complete fully or not happen at all—no partial updates.
C — Consistency (Rules Must Always Hold)
Consistency ensures the database always moves from one valid state to another valid state.
This means:
- Reads return valid data from the database
- Writes must follow database rules/constraints (like primary keys, foreign keys, checks, etc.)
Example: If a foreign key requires a related record to exist, the database won’t allow an update that breaks that relationship.
I — Isolation (Transactions Don’t Interfere)
Isolation means concurrent transactions should not affect each other’s intermediate work.
If Transaction 1 is still running:
- Transaction 2 should not see Transaction 1’s changes until Transaction 1 commits.
This prevents issues like dirty reads and inconsistent results when many users are updating data at the same time.
D — Durability (Committed Means Permanent)
Durability guarantees that once a transaction is committed, it stays committed—even if:
- the system crashes
- power fails
- the database restarts
Most database management systems (DBMS) ensure durability using Write-Ahead Logging (WAL), where changes are recorded in a log before being applied to the main database files.
Comments
Post a Comment