ACID
ACID describes guarantees expected from database transactions. It is important for systems where partial writes, invalid state, concurrent changes, or lost data would create serious correctness problems.
Overview
Section titled “Overview”| Letter | Term | Meaning |
|---|---|---|
| A | Atomicity | A transaction fully completes or fully rolls back |
| C | Consistency | A transaction moves the database from one valid state to another valid state |
| I | Isolation | Concurrent transactions should not corrupt each other |
| D | Durability | Committed data should survive failures |
Atomicity
Section titled “Atomicity”Atomicity means a transaction is treated as one unit.
If one part fails, the whole transaction should be rolled back. This prevents partial updates.
BEGIN;
UPDATE accountsSET balance = balance - 100WHERE id = 1;
UPDATE accountsSET balance = balance + 100WHERE id = 2;
COMMIT;Consistency
Section titled “Consistency”Consistency means transactions should preserve database rules.
Rules can include primary keys, foreign keys, check constraints, not null constraints, and application-level invariants.
Isolation
Section titled “Isolation”Isolation controls how concurrent transactions see each other’s changes.
Without proper isolation, two users or processes can read and write overlapping data in ways that produce incorrect results.
Durability
Section titled “Durability”Durability means that once a transaction is committed, the database should keep that committed result even after a crash or restart.
Database systems use mechanisms such as logs, checkpoints, and storage synchronization to support durability.
Common confusion
Section titled “Common confusion”- ACID atomicity is about all-or-nothing transactions.
- Atomic value in relational modeling is about one indivisible value in a table cell.
- Consistency in ACID does not mean every business rule is magically correct. The rules must be defined and enforced.
- Isolation level is configurable in many databases, so behavior can differ by database and configuration.