Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Papers We Love SF - Sagas

Papers We Love SF - Sagas

A talk about Sagas https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf

And the application of them in Distributed Systems

Caitie McCaffrey

March 18, 2016
Tweet

More Decks by Caitie McCaffrey

Other Decks in Technology

Transcript

  1. –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.”
  2. “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.
  3. “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.”
  4. Saga Guarantee Either • T1, T2 … Tn or •

    T1, T2 … Tj, Cj, … C2, C1
  5. • Book Hotel (T1 ) • Book Car (T2 )

    • Book Flight (T3 ) • Cancel Hotel (C1 ) • Cancel Car (C2 ) • Cancel Flight (C3 ) Sagas
  6. Saga Log • Begin Saga • End Saga • Abort

    Saga • Begin Ti • End Ti • Begin Ci • End Ci
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. –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
  26. \ • Book Hotel (T1 ) • Book Car (T2

    ) • Book Flight (T3 ) • Cancel Hotel (C1 ) • Cancel Car (C2 ) • Cancel Flight (C3 ) Requests instead of Transactions
  27. A Distributed Saga is a Collection of Sub-Requests Each Sub-Request

    has a Compensating Request T1, T2 … Tn C1, C2 … Cn
  28. 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
  29. Saga Execution Coordinator (SEC) • Interprets & Writes to Saga

    Log • Applies Saga Sub-Requests • Applies Saga Compensating Requests when Necessary
  30. Safe States • All Executed Sub-Requests are Complete (Start Ti

    & End Ti both logged) • Saga has been Aborted, Proceed with Compensating Transactions
  31. Un-Safe State • Start Ti logged, no End Ti logged

    Abort Saga Start Compensating Requests
  32. Distributed Saga Guarantee Either • T1, T2 … Tn or

    • T1, T2 … Tj, Cj, … C2, C1
  33. Distributed Sagas • Distributed/Durable Saga Log • SEC Process •

    Compensating Requests: Idempotent & Commutative
  34. Sagas • Long Lived / Distributed Transactions • Trade Atomicity

    for Availability • Failure Management Pattern