Skip to content
KinPilot™Learn & Explore
Menu

Grades 9–12 · Computing

Why does an atomic transaction accept all its changes or none?

A transaction groups related database changes into one operation. Atomic means all or nothing: its completed effects are accepted together, or the grouped changes are canceled. The transaction boundary matters because an individual internal step is not necessarily a valid result for the application.

D26 visual explanationTwo fictional inventory records begin A=8 and B=3. A transfer of 2 units commits both updates. Visible final values are A=6, B=5, total 11. Atomicity means neither a debit-only nor credit-only final state is accepted. Concurrency and external side effects are outside this small model.A transaction commits all changes or noneVisible before: A = 8 · B = 3 · total = 11One atomic transactionDebit A by 2Credit B by 2Given signal: no interruptionCOMMIT both changesVisible after: A = 6 · B = 5 · total = 11No debit-only or credit-only final state is accepted.

In the diagramA transaction commits all changes or noneVisible before: A = 8 · B = 3 · total = 11One atomic transactionDebit A by 2Credit B by 2Given signal: no interruptionCOMMIT both changesVisible after: A = 6 · B = 5 · total = 11No debit-only or credit-only final state is accepted.

The successful two-unit transfer commits A=6 and B=5 together, preserving the total of eleven units.

Two fictional inventory records begin with A holding eight units and B holding three. A transfer of two units requires subtracting two from A and adding two to B. A completed transfer leaves A at six and B at five. The total remains eleven because the intended updates subtract and add the same amount.

The first internal update might occur before the second. If an interruption happens after the debit, the system must not accept A at six and B at three as the final transfer. Rollback cancels the grouped changes, returning the visible records to eight and three. Commit instead accepts both successfully completed updates together.

The toy also checks that A has enough units before allowing the transfer. That rule is separate from atomicity. An all-or-nothing operation could still contain the wrong calculations if its application rules were wrong. Atomicity makes the group indivisible; it does not supply every other correctness condition.

This transaction covers only the stated database changes. Sending an unrelated message or changing another external system would require additional coordination. Concurrent transactions and persistent storage raise other guarantees. Keeping those distinctions explicit makes the all-or-nothing promise precise rather than treating it as a promise that every part of a larger workflow is automatically reliable.

About this explanation

Starting knowledge: Track changes to two stored quantities and distinguish an intermediate step from an accepted final result.

Sources

  • PostgreSQL Global Development Group — Transactions: all-or-nothing updates
← Grades 9–12 topics