Limited Offer

30% OFF Lifetime Access ($139) with code SYSTEM30

TOPIC #42Beginner 9 min read

ACID Properties (Atomicity, Consistency, Isolation, Durability)

πŸ’‘
Core Architecture Summary

Deconstruct the 4 guarantees of transactional databases: WAL-based rollback, schema invariance, MVCC isolation, and fsync durability.

Key Glossary Concepts in this TopicAll Glossary Terms

ACID Transaction Execution Pipeline & WAL Recovery Flow πŸ›‘οΈ

How Relational Database Management Systems implement Atomicity (WAL Undo), Consistency (Constraints), Isolation (MVCC Locks), and Durability (fsync).

ACID Transaction Execution Pipeline & WAL Recovery Flow πŸ›‘οΈ
100%
Rendering visual architecture flowchart...

01.1. The 4 Pillars of ACID Transactions

A Database Transaction is a sequence of read and write operations executed as a single, logical unit of work. To guarantee reliable data processing in the presence of concurrent users, network partitions, and hardware crashes, a transactional database must satisfy the ACID guarantees:

1. Atomicity ("All or Nothing")

Every statement in a transaction (INSERT, UPDATE, DELETE) is treated as a single indivisible operation. Either all operations succeed and commit, or if any error occurs (e.g., constraint violation, system crash, deadlock), the database rolls back all previous mutations, leaving the database in its exact pre-transaction state.

  • Mechanism: Implemented via Write-Ahead Log (WAL) Undo Records or Rollback Segments.

2. Consistency ("Valid State Invariance")

A transaction can only transition the database from one valid state to another valid state, strictly preserving all schema constraints, foreign key relationships, check constraints, and unique indexes. If a transaction attempts to insert a record violating a CHECK (balance >= 0) constraint, the engine aborts the transaction.

3. Isolation ("Invisible Intermediate States")

Concurrent transactions executing simultaneously cannot observe each other's partial, uncommitted intermediate writes. To an external observer, concurrent transactions appear to execute sequentially.

  • Mechanism: Implemented via Multi-Version Concurrency Control (MVCC) and Two-Phase Locking (2PL).

4. Durability ("Survives Power Outages")

Once a transaction commits and the database returns a success code to the client, its changes are permanently recorded in non-volatile storage. Even if the database server loses power 1 millisecond later, the data is guaranteed to survive.

  • Mechanism: Implemented via synchronous fsync() of WAL log records to persistent disk platters/flash before acknowledging the commit.

02.2. The ARIES Recovery Algorithm (How Databases Survive Crashes)

When a database crashes mid-transaction and reboots, how does it guarantee Atomicity and Durability? It runs the ARIES (Algorithms for Recovery and Isolation Exploiting Semantics) recovery process across the Write-Ahead Log:

  1. Analysis Phase: Scans the WAL forward from the last safe checkpoint to identify:
    • Which transactions were committed (Winners).
    • Which transactions were uncommitted and running when the crash occurred (Losers).
  2. Redo Phase (Repeating History): Scans the WAL forward, re-applying all committed changes to data pages to restore the exact memory state at the moment of the crash (Durability).
  3. Undo Phase (Rolling Back Losers): Scans the WAL backward, executing inverse operations to rollback all uncommitted changes made by loser transactions (Atomicity).
sqlβ€” Atomic Bank Transfer in PostgreSQL using ACID Transaction block
BEGIN; -- Start atomic transaction

-- Step 1: Debit sender
UPDATE accounts 
SET balance = balance - 100.00 
WHERE id = 1 AND balance >= 100.00;

-- Step 2: Credit receiver
UPDATE accounts 
SET balance = balance + 100.00 
WHERE id = 2;

-- If both steps succeed without constraint violations:
COMMIT; 
-- If an error occurs, the application issues:
-- ROLLBACK;

βš–οΈArchitectural Trade-offs & Production Realities

Architectural Advantages

  • Eliminates data corruption and phantom financial losses by guaranteeing total transactional integrity.
  • Developers write clean business logic without worrying about manual rollback handling during crashes.
  • Durability guarantees zero data loss (RPO=0) for mission-critical workloads.

Trade-offs & Constraints

  • Synchronous disk fsync writes on every commit cap single-node write throughput (mitigated by Group Commit batching).
  • High isolation levels (Serializable) increase lock contention and transaction abort rates under high concurrency.
Production Implementation in Big Tech
Stripe & PostgreSQLβ€’ ACID Financial Ledger Processing

Stripe executes all payment transfers inside strict ACID transaction blocks in PostgreSQL clusters. If a network timeout or credit card gateway failure occurs halfway through processing a multi-party payout, PostgreSQL rolls back all partial database mutations atomically, guaranteeing that ledger credits and debits always balance to zero.

🎯 Staff+ Engineering Takeaways

  • ACID = Atomicity (all or nothing), Consistency (valid state), Isolation (independent execution), Durability (survives crashes).
  • Atomicity uses WAL Undo records; Durability uses WAL Redo logs + fsync().
  • ARIES recovery algorithm runs Analysis, Redo, and Undo phases on reboot.
  • ACID trades raw write speed for mathematical data correctness.

Topic Knowledge Assessment 🧠

Step through 2 scenario questions to test your staff-level grasp.

Question 1 of 20 answered
#1

Which component of a database engine is responsible for guaranteeing the "D" (Durability) in ACID when a power failure occurs immediately after a transaction commits?

Rate This Architecture Chapter4.9 / 5.0 (38 ratings)

How clear and staff-actionable was this system breakdown?