Ctrl K

ACID

A transaction reliability model based on atomicity, consistency, isolation, and durability.

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

LetterTermMeaning
AAtomicityA transaction fully completes or fully rolls back
CConsistencyA transaction moves the database from one valid state to another valid state
IIsolationConcurrent transactions should not corrupt each other
DDurabilityCommitted data should survive failures

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 accounts
SET balance = balance - 100
WHERE id = 1;

UPDATE accounts
SET balance = balance + 100
WHERE id = 2;

COMMIT;

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

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

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

  • 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.