Atomicity

Atomicity ensures the All-or-Nothing behavior of a transaction.

Nov 15, 2025

Atomicity is a basic property in database systems that ensures a transaction, a sequence of one or more operations, is executed completely or not at all. There is no middle ground or partial execution.

This represents the ‘A’ in the ACID (Atomicity, Consistency, Isolation, Durability) model.

Eg:

Bank Transfer: Transferring £100 from Account A to Account B requires two operations:

  1. Debit £100 from Account A
  2. Credit £100 to Account B

With atomicity, either both operations succeed (money is transferred) or both fail (money stays in Account A). The system cannot debit Account A without crediting Account B.

All-or-Nothing

The most common mechanism used by databases to ensure atomicity is Transaction Logging (often a Write-Ahead Log).

  • Write-Ahead Logging (WAL): Before the database modifies any actual data on disk (e.g., the account balances), it first writes a description of the intended change to a separate, sequential file called a transaction log.
  • Commit: A transaction is considered “committed” not when the data tables are written, but when its log records have been successfully flushed to durable storage.
  • Rollback: This log is what enables the rollback.
    • Rollback: If an operation fails (e.g., Account A has insufficient funds), the application issues a ROLLBACK command. The database uses the log to find all changes made by this transaction and undoes them in reverse order.
    • Recovery: If the server loses power, the database runs a recovery process on restart. It reads the transaction log to:
      • Roll Back any changes from transactions that were not marked as committed. This handles the Failure path.
      • Roll Forward any changes from transactions that were marked “committed” but whose changes might not have made it to the main data files yet. This ensures the Changes Permanent state.

Performance

The act of writing to a log before writing to the data files introduces write overhead (latency). This is the price paid for the guarantee of correctness and the ability to recover from failure.

Atomicity vs. Isolation

Atomicity defines the all-or-nothing behavior of a single transaction.

Isolation (the ‘I’ in ACID) defines how a transaction behaves in the presence of other concurrent transactions. It prevents concurrent transactions from interfering with each other’s data.

Further Reading