liveBook · Manning

Chapter 9: Implementing system commands with sagas

What you will learn in chapter 9 of Microservices Patterns, Second Edition

The chapter introduces sagas as a service collaboration pattern for commands that update data across multiple services.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces sagas as a service collaboration pattern for commands that update data across multiple services.

Key terms: IPC mechanisms, service collaboration patterns, Saga pattern, distributed system commands

9.1 Transaction management in a microservice architecture

Introduces the transaction-management challenge for system commands that modify data across multiple microservices.

Key terms: system operation, transactional boundaries, consistency

9.1.1 System commands need to be transactional

This section explains why system commands need transaction boundaries, what transactions and ACID guarantee, and why a single-database monolith can apply those guarantees straightforwardly.

Key terms: system command, partial failure, concurrency, invariant, availableCredit, transaction, unit of work, transaction boundary, commit, abort

9.1.2 ACID transactions in a microservice architecture

Explains how distributed ACID transactions work and why they are usually a poor fit for system commands that span microservices.

Key terms: system commands, ACID transactions, distributed system commands, createOrder(), XA, global transaction, global transaction identifier, XA-compliant, two-phase commit (2PC), transaction coordinator

9.2 Using the Saga pattern

This section introduces sagas as a way to implement system commands across services using local transactions, and explains how they differ from ACID transactions.

Key terms: Saga pattern, system command, local transactions, saga steps, saga step, service operation, business logic, persistent entities, saga participant, compensating transactions

9.2.1 An example saga: The Create Order saga

The section develops the Create Order saga from a happy-path sequence into one that compensates for business-rule failures and prevents other transactions from acting on an unfinished order.

Key terms: Create Order saga, createOrder(), reserveCredit(), rejectOrder(), compensating transaction, failure, business rule, technical failures, semantic lock, application-level locking

9.2.2 The structure of a saga

This section explains how a saga’s steps are organized around a pivot transaction and why steps before and after it have different rollback and retry requirements.

Key terms: pivot transaction, go/no-go point, compensating transaction, reserveCredit(), compensatable transactions, forward transaction, retriable transactions, transient technical failure, approveOrder(), PENDING state

9.2.3 Overview of saga coordination

This section explains how saga coordination advances steps and passes data, then examines response timing, parallel execution, timeouts, and two ways to organize coordination.

Key terms: coordination logic, saga participant, local transaction, compensating transactions, final outcome, partial outcome, runtime coupling, 202 (Accepted), 201 (Created), sequentially

9.2.4 Benefits and drawbacks of sagas

This section weighs sagas’ runtime and deployment benefits against their isolation and rollback drawbacks.

Key terms: loose runtime coupling, deployment simplicity, ephemeral service instances, lack of isolation, lack of automatic rollback, compensating transactions

9.3 Handling saga’s lack of isolation

This section explains why sagas lack ACID isolation, how that can cause anomalies, and why reduced isolation can still be workable.

Key terms: ACID, isolation, ACD, atomicity, consistency, durability, anomaly, compensating transaction, serially, reduced isolation

9.3.1 Overview of anomalies

This section explains how concurrent sagas can violate business invariants despite correct local transactions, using two order-processing examples.

Key terms: isolation, serialization anomalies, global isolation, dirty reads, nonrepeatable reads, phantom reads, lost updates, write skew, business invariant, Create Order Saga

9.3.2 Countermeasures for handling the lack of isolation

The section explains six countermeasures for preventing or reducing business problems caused by sagas’ lack of transaction isolation.

Key terms: semantic lock, *_PENDING states, APPROVAL_PENDING, compensatable transaction, retriable transaction, compensating transaction, commutative updates, lost updates, debit(), credit()

9.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 8: Interprocess communication in a microservice architecture Chapter 10: Saga coordination mechanisms →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.