liveBook · Manning

Atomicity

As explained in Microservices Patterns, Second Edition

Atomicity is the transaction property that all operations succeed as one unit or the transaction has no effect.

Atomicity makes a transaction all-or-nothing: every operation succeeds as one unit, or the transaction has no effect. For system commands, this prevents partial changes when a command fails. section 9.1.1

BEGIN TRANSACTION

SELECT * FROM PRODUCTS WHERE PRODUCT_ID = ?

UPDATE CONSUMER
  SET AVAILABLE_CREDIT = AVAILABLE_CREDIT - ?
  WHERE CONSUMER_ID = ?
    AND AVAILABLE_CREDIT >= ?

INSERT INTO ORDERS (...) VALUES (...)
COMMIT TRANSACTION

A product lookup, credit deduction, and order insertion are grouped between transaction boundaries, so the command’s operations succeed or fail together. section 9.1.1

Choose the transaction boundary according to where the command’s work occurs:

  • For operations local to one service, use a local ACID transaction to provide atomicity. section 9.4
  • For operations spanning services, use a saga of local transactions; the saga itself is not ACID, and compensating transactions may undo prior steps. section 9.4

How Microservices Patterns, Second Edition covers it

How deep it goes
Explains the all-or-nothing guarantee and its role in commands, with transaction examples but little implementation detail.
Examples
Groups a product lookup, credit deduction, and order insertion within one transaction.
What you can do after
Apply atomicity through local ACID transactions to prevent system commands from leaving partial effects.
How it connects
Connects atomicity to ACID transactions, isolation, and saga-based distributed operations.

Also explained in

Compare how 19 books explain atomicity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.