Microservices Pattern: Saga

Status:: 🟩
Links:: Saga Pattern

Metadata

Authors:: Richardson, Chris
Title:: Microservices Pattern: Saga
Date:: 2017
URL:: https://microservices.io/patterns/data/saga.html
DOI::

Bibliography

Richardson, C. (2017). Microservices Pattern: Saga. Microservices.Io. https://microservices.io/patterns/data/saga.html

Zotero

Type:: #zotero/webpage
Zotero::

Keywords:: [Saga Pattern]

Relations

Abstract

Implement transactions using a saga, which is sequence of local transactions

Notes & Annotations

📑 Annotations (imported on 2024-01-17#15:48:08)

richardson.2017.microservicespatternsaga (pg. 1)

Implement each business transaction that spans multiple services as a saga. A saga is a sequence of local transactions. Each local transaction updates the database and publishes a message or event to trigger the next local transaction in the saga. If a local transaction fails because it violates a business rule then the saga executes a series of compensating transactions that undo the changes that were made by the preceding local transactions.

richardson.2017.microservicespatternsaga (pg. 1)

There are two ways of coordination sagas:

  • Choreography - each local transaction publishes domain events that trigger local transactions in other services
  • Orchestration - an orchestrator (object) tells the participants what local transactions to execute
richardson.2017.microservicespatternsaga (pg. 3)

In order to be reliable, a service must atomically update its database and publish a message/event. It cannot use the traditional mechanism of a distributed transaction that spans the database and the message broker.

richardson.2017.microservicespatternsaga (pg. 3)

The following patterns are ways to atomically update state and publish messages/events:

  • Event sourcing
  • Transactional Outbox