liveBook · Manning

Database transaction

As explained in Grokking Software Architecture

A unit of database work treated as a single operation with defined consistency and recovery behavior.

Imagine buying the last pair of sneakers in a flash sale. The inventory must decrease and an order must be created together—not leave one without the other. A database transaction treats that work as a single unit. section 8.2.1

ACID describes the guarantees behind that unit of work:

  • Atomicity: All steps succeed together, or the database rolls them back. A payment timeout should not leave the sneaker deducted without an order. section 8.2.1
  • Consistency: A transaction moves the database between valid states. An inventory constraint can reject a purchase that would bring stock below zero. section 8.2.1
  • Isolation: Transactions do not interfere with one another. In the sale example, another reader sees the inventory before or after the purchase, not its half-finished calculation. section 8.2.1
  • Durability: Once committed, a transaction is permanent, even if power fails immediately afterward. section 8.2.1

Durability is not a backup. It protects committed data from failures such as a power interruption; it does not undo an accidental deletion. section 8.2.1

How Grokking Software Architecture covers it

How deep it goes
Explains each ACID guarantee through a worked scenario and distinguishes durability from backup.
Examples
Illustrates a flash-sale purchase with inventory and order records, a payment timeout, and an accidental deletion.
What you can do after
Evaluate transaction guarantees and distinguish durability from backup protection.
How it connects
Connects transactions to ACID, database constraints, rollback, and backups.

Also explained in

Compare how 21 books explain database transaction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.