applying the saga pattern - goto conference · end book flight (t 3) end saga successful saga....

90
Applying the Saga Pattern Caitie McCafffrey

Upload: others

Post on 11-Oct-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Applying the Saga PatternCaitie McCafffrey

Page 2: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Caitie McCaffrey!Distributed Systems Engineer

@CaitieCaitieM.com

Page 3: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 4: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

• Why Sagas?

• Sagas Paper

• Distributed Sagas

• Sagas in Halo 4

Page 5: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Systems Used to Be Simple

Page 6: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Serializability & ACID

Page 7: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

SOA/Microservices

Page 8: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Two Phase Commit

Page 9: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

2PC: Prepare Phase

Page 10: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

2PC: Commit Phase

Page 11: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

2PC Doesn’t Scale

• O(n^2) Messages

• Coordinator: Single Point of Failure

• Reduced Throughput

Page 12: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

SpannerGoogle’s Globally-Distributed Database

Corbett et. al.

Page 13: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

–Corbett et al.

“Spanner is Google’s scalable, multi-version, globally distributed, and synchronously-replicated database. It is the first system to distribute data at global scale and support

externally-consistent distributed transactions.”

Page 14: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

“The key enabler of these properties is a new TrueTime API

and its implementation…using multiple modern clock references

(GPS and atomic clocks).”

–Corbett et al.

Page 15: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Spanner is Expensive & Proprietary

• Custom Hardware & Data-Centers

• Synchronization Not Solved

Page 16: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Distributed Transactions are Hard & Expensive

Page 17: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Can We Do Better?

Page 18: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Can We Do Better?

Page 19: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Sagas Hector Garcia-Molina, Kenneth Salem

Princeton University 1987

Page 20: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Sagas are Long Lived Transactions

Page 21: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

“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.”

Page 22: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

A Saga is a Collection of Sub-Transactions

T1, T2 … Tn

Page 23: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Each Sub-Transaction has a Compensating Transaction

C1, C2 … Cn

Page 24: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Cn Semantically Undoes Tn

Page 25: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Saga Guarantee Either

• T1, T2 … Tn or

• T1, T2 … Tj, Cj, … C2, C1

Page 26: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Trade-Off: Atomicity for Availability

Page 27: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Sagas are a Failure Management Pattern

Page 28: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Large Single Transaction

Page 29: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

• Book Hotel (T1)

• Book Car (T2)

• Book Flight (T3)

• Cancel Hotel (C1)

• Cancel Car (C2)

• Cancel Flight (C3)

Sagas

Page 30: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Saga Execution Coordinator

(SEC)

Page 31: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Saga Log

• Begin Saga

• End Saga

• Abort Saga

• Begin Ti

• End Ti

• Begin Ci

• End Ci

Page 32: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga!

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

End Book Car Rental (T2)

Start Book Flight (T3)

End Book Flight (T3)

End Saga

Successful Saga

Page 33: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)!

End Book Hotel (T1)

Start Book Car Rental (T2)

End Book Car Rental (T2)

Start Book Flight (T3)

End Book Flight (T3)

End Saga

Successful Saga

Page 34: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)!

Start Book Car Rental (T2)

End Book Car Rental (T2)

Start Book Flight (T3)

End Book Flight (T3)

End Saga

Successful Saga

Page 35: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)!

End Book Car Rental (T2)

Start Book Flight (T3)

End Book Flight (T3)

End Saga

Successful Saga

Page 36: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

End Book Car Rental (T2)!

Start Book Flight (T3)

End Book Flight (T3)

End Saga

Successful Saga

Page 37: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

End Book Car Rental (T2)

Start Book Flight (T3)!

End Book Flight (T3)

End Saga

Successful Saga

Page 38: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

End Book Car Rental (T2)

Start Book Flight (T3)

End Book Flight (T3)!

End Saga

Successful Saga

Page 39: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

End Book Car Rental (T2)

Start Book Flight (T3)

End Book Flight (T3)

End Saga

Successful Saga

Page 40: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Unsuccessful SagaBackwards Recovery

Page 41: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga!

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

Abort Saga

Start Compensate Car Rental (C2)

End Compensate Car Rental (C2)

Start Compensate Book Hotel (C1)

End Compensate Book Hotel (C1)

End Saga

Unsuccessful Saga

Page 42: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)!

End Book Hotel (T1)

Start Book Car Rental (T2)

Abort Saga

Start Compensate Car Rental (C2)

End Compensate Car Rental (C2)

Start Compensate Book Hotel (C1)

End Compensate Book Hotel (C1)

End Saga

Unsuccessful Saga

Page 43: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)!

Start Book Car Rental (T2)

Abort Saga

Start Compensate Car Rental (C2)

End Compensate Car Rental (C2)

Start Compensate Book Hotel (C1)

End Compensate Book Hotel (C1)

End Saga

Unsuccessful Saga

Page 44: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)!

Abort Saga

Start Compensate Car Rental (C2)

End Compensate Car Rental (C2)

Start Compensate Book Hotel (C1)

End Compensate Book Hotel (C1)

End Saga

Unsuccessful Saga

Page 45: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

Abort Saga!

Start Compensate Car Rental (C2)

End Compensate Car Rental (C2)

Start Compensate Book Hotel (C1)

End Compensate Book Hotel (C1)

End Saga

Unsuccessful Saga

Page 46: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

Abort Saga

Start Compensate Car Rental (C2)!

End Compensate Car Rental (C2)

Start Compensate Book Hotel (C1)

End Compensate Book Hotel (C1)

End Saga

Unsuccessful Saga

Page 47: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

Abort Saga

Start Compensate Car Rental (C2)

End Compensate Car Rental (C2)!

Start Compensate Book Hotel (C1)

End Compensate Book Hotel (C1)

End Saga

Unsuccessful Saga

Page 48: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

Abort Saga

Start Compensate Car Rental (C2)

End Compensate Car Rental (C2)

Start Compensate Book Hotel (C1)!

End Compensate Book Hotel (C1)

End Saga

Unsuccessful Saga

Page 49: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

Abort Saga

Start Compensate Car Rental (C2)

End Compensate Car Rental (C2)

Start Compensate Book Hotel (C1)

End Compensate Book Hotel (C1)!

End Saga

Unsuccessful Saga

Page 50: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel (T1)

End Book Hotel (T1)

Start Book Car Rental (T2)

Abort Saga

Start Compensate Car Rental (C2)

End Compensate Car Rental (C2)

Start Compensate Book Hotel (C1)

End Compensate Book Hotel (C1)

End Saga

Unsuccessful Saga

Page 51: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

–Molina et. al

“Due to space limitations, we only discuss Sagas in a centralized

System, although clearly they can be implemented in a distributed

database system.”

Sagas in Distributed Systems

Page 52: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

SOA/Microservices

Page 53: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

\• Book Hotel (T1)

• Book Car (T2)

• Book Flight (T3)

• Cancel Hotel (C1)

• Cancel Car (C2)

• Cancel Flight (C3)

Requests instead of Transactions

Page 54: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

A Distributed Saga is a Collection of Sub-Requests

Each Sub-Request has a Compensating Request

T1, T2 … Tn

C1, C2 … Cn

Page 55: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Begin Saga

Start Book Hotel Request (T1)

End Book Hotel Request (T1)

Start Book Car Rental Request (T2)

End Book Car Rental Request (T2)

Start Book Flight Request (T3)

End Book Flight Request (T3)

End Saga

Successful Distributed Saga

Page 56: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Saga LogDurable & Distributed

Page 57: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Saga Execution Coordinator (SEC)

• Interprets & Writes to Saga Log

• Applies Saga Sub-Requests

• Applies Saga Compensating Requests when Necessary

Page 58: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 59: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 60: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 61: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 62: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 63: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 64: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 65: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 66: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 67: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Apply Compensating Requests

•Aborted Saga Response

•Start Request Fails

•SEC Crashes (non-safe state)

Page 68: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 69: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 70: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 71: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

What Happens when Compensating Requests Fail?

Page 72: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Compensating Requests Must Be

Idempotent

Page 73: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

What Happens when SEC Fails?

Page 74: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Safe States

• All Executed Sub-Requests are Complete (Start Ti & End Ti both logged)

• Saga has been Aborted, Proceed with Compensating Transactions

Page 75: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Un-Safe State

• Start Ti logged, no End Ti logged

Abort Saga

Start Compensating Requests

Page 76: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Request Messaging Semantics

• Sub-Requests (Ti): At Most Once

• Compensating Requests (Ci): At Least Once

Page 77: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Distributed Saga Guarantee

Either

• T1, T2 … Tn or

• T1, T2 … Tj, Cj, … C2, C1

Page 78: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Distributed Sagas

• Distributed/Durable Saga Log

• SEC Process

• Compensating Requests: Idempotent

Page 79: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel
Page 80: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Halo Statistics

Page 81: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Halo Statistics Service

Page 82: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Halo Statistics Service with Sagas

Page 83: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Forward-Recovery

Page 84: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Store Stats Player One

Store Stats Player Two

Store Stats Player Three

Store Stats Player Four

Game Grain / SEC

Page 85: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Forward Recovery Sub-Requests Must Also Be

Idempotent

Page 86: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Store Stats Player One

Store Stats Player Two

Store Stats Player Three

Store Stats Player Four

Game Grain / SEC

Page 87: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Store Stats Player One

Store Stats Player Two

Store Stats Player Three

Store Stats Player Four

Game Grain / SEC

Page 88: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Sagas

• Long Lived / Distributed Transactions

• Trade Atomicity for Availability

• Failure Management Pattern

Page 89: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Thank You

• @pbailis

• @randommood

• @tsantero

• @aphyr

• @jmhodges

• @clemnsv

Page 90: Applying the Saga Pattern - GOTO Conference · End Book Flight (T 3) End Saga Successful Saga. Unsuccessful Saga Backwards Recovery. Begin Saga! Start Book Hotel (T 1) End Book Hotel

Questions?Please remember to evaluate via the GOTO Guide App

@Caitie