liveBook · Manning

Transaction boundary

As explained in Microservices Patterns, Second Edition

A transaction boundary defines the scope within which operations are governed by rules for success, failure, concurrency, conflicts, and visibility.

A transaction boundary groups operations into a unit of work governed by rules for success, failure, concurrency, conflicts, and visibility. Changes commit together when operations succeed and required invariants hold; failures abort the transaction so partial changes do not undermine correctness. section 9.1.1

In a microservice architecture, each service defines its own boundary. A command or query spanning services therefore cannot run as one ACID transaction: participating services perform local transactions. Commands can use a saga; queries rely on multiple independent transactions. section 9.1 section 12.1.5

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 transaction encloses a product lookup, a conditional credit update, and an order insertion, then commits the changes together. section 9.1.1

Treat service placement as consequential: service boundaries also divide processes and transactions. Distributed operations add network failure and availability concerns, so weigh those costs against the design’s needs. section 1.3.4 section 7.5.3

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines commit and abort behavior, invariants, conflicts, isolation, and visibility, then relates local transactions to cross-service operations.
Examples
Uses a product lookup, conditional customer-credit update, and order insertion as one SQL transaction.
What you can do after
Understand why cross-service commands and queries cannot rely on one ACID transaction.
How it connects
Links transaction boundaries to ACID transactions, sagas, eventual consistency, and microservices.

Also explained in

Compare how 2 books explain transaction boundary →

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.