The document describes distributed sagas, a protocol for coordinating microservices. Distributed sagas define a directed acyclic graph of requests and compensating requests that represent a single business transaction. A saga execution coordinator executes the requests, tracking their state in a fault-tolerant log. This allows transactions to complete fully or be compensated if a request fails, without the need for two-phase commit across services. Distributed sagas provide isolation and modularity to microservices architectures compared to other approaches to distributed transactions.
29. 2PC: Commit Front End
Trips
Done
Done
Done
Doesn’t Scale
•O (N^2) Messages in the worst case
•Coordinator is a Single Point of Failure
•Reduced Throughput
33. 1987
“A Saga is a Long Lived Transaction that
can be written as a sequence of transactions
that can be interleaved.
All transactions in the sequence complete
successfully or compensating transactions
are ran to amend a partial execution.”
35. A Distributed Saga is a Collection of Requests
Book Hotel Book Car Book Flight Charge Money
36. A Distributed Saga is a Collection of Requests
Book Hotel Book Car Book Flight Charge Money
and Compensating Requests
Cancel Hotel Cancel Car Cancel Flight Refund Money
37. A Distributed Saga is a Collection of Requests
Book Hotel Book Car Book Flight Charge Money
and Compensating Requests
Cancel Hotel Cancel Car Cancel Flight Refund Money
that represent a single business level action
62. Distributed Saga Guarantee
Book Hotel Book Car Book Flight Charge Money
All requests were completed successfully
Or a subset of requests and the corresponding
compensating requests were executed
Book Hotel Book Car Cancel Hotel Cancel Car
63. Distributed Saga Guarantee
Book Hotel Book Car Book Flight Charge Money
All requests were completed successfully
Or a subset of requests and the corresponding
compensating requests were executed
Book Hotel Book Car Cancel Hotel Cancel Car
No Atomicity
No Isolation
64. Distributed Saga Guarantee
Book Hotel Book Car Book Flight Charge Money
All requests were completed successfully
Or a subset of requests and the corresponding
compensating requests were executed
Book Hotel Book Car Cancel Hotel Cancel Car
No Atomicity
No Isolation
Book Hotel
Book Car
Visible before
Saga Completes
65. Distributed Saga Guarantee
Book Hotel Book Car Book Flight Charge Money
All requests were completed successfully
Or a subset of requests and the corresponding
compensating requests were executed
Book Hotel Book Car Cancel Hotel Cancel Car
91. Car FlightHotel
Payment
Start Saga
End Saga
SagaLog
Start Saga
SEC
Start Hotel
End Hotel
Start Car
End Car
Start Flight
Done
End Flight
Start Payment
Payment
Request
92. Car FlightHotel
Payment
Start Saga
End Saga
SagaLog
Start Saga
SEC
Start Hotel
End Hotel
Start Car
End Car
Start Flight
End Payment
End Flight
Start Payment
Payment
Response
93. Car FlightHotel
Payment
Start Saga
End Saga
SagaLog
Start Saga
SEC
Start Hotel
End Hotel
Start Car
End Car
Start Flight
End Flight
Start Payment
End Payment
Done
94. Car FlightHotel
Payment
Start Saga
End Saga
SagaLog
Start Saga
SEC
Start Hotel
End Hotel
Start Car
End Car
Start Flight
End Flight
Start Payment
End Payment
End Saga
95. Car FlightHotel
Payment
Start Saga
End Saga
SagaLog
Start Saga
SEC
Start Hotel
End Hotel
Start Car
End Car
Start Flight
End Flight
Start Payment
End Payment
Done
End Saga
96. Car FlightHotel
Payment
Start Saga
End Saga
SagaLog
Start Saga
SEC
Start Hotel
End Hotel
Start Car
End Car
Start Flight
End Flight
Start Payment
End Payment
End Saga
122. Distributed Saga Guarantee
Book Hotel Book Car Book Flight Charge Money
All requests were completed successfully
Or a subset of requests and the corresponding
compensating requests were executed
Book Hotel Book Car Cancel Hotel Cancel Car
128. with Distributed Sagas
Isolation of Complex Code
Fron
Tr
Complex Code
Lives Everywhere
Front
SEC
SagaLog
Complex Code
Lives Here
Complex Code
Lives Here