Web apps & software

What are ACID transactions?

ACID describes four properties of a database transaction: atomicity, consistency, isolation and durability. Together they ensure a group of changes either completes fully or not at all, and survives a crash.

The four letters

  • Atomicity: moving a booking from "pending" to "assigned" and inserting a driver log row happen together; if the second step fails, the first is undone.
  • Consistency: the database's rules, such as foreign keys and unique constraints, hold before and after.
  • Isolation: two dispatchers assigning the last available driver at the same moment do not both succeed.
  • Durability: once the commit is confirmed, power loss does not erase it.

Why you care

Anything involving money, stock or scarce slots needs these properties. Relational databases such as PostgreSQL, MySQL with InnoDB and SQL Server provide them well. Some NoSQL systems relax parts of ACID for speed or scale, and newer versions of MongoDB support multi-document transactions.

Cost

Stronger isolation means more locking and some waiting. Keep transactions short and avoid holding one open while calling an outside API.

Questions, answered

Mainstream relational databases are. Many NoSQL stores offer limited guarantees per record instead of across records.

Two transactions each wait for a lock the other holds. The database cancels one so the other can proceed.

By the Stegnor team · Updated