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

Distributed Sagas: A Protocol for Coordinating ...

Distributed Sagas: A Protocol for Coordinating Microservices

Microservices have become the defacto architecture pattern for building services. However separating business logic into small services that operate with a single logical data set has introduced consistency challenges. Previous attempts to solve this problem like two phase commit have not been widely adopted due to availability and liveness issues.

Instead developers implement feral concurrency control mechanism. This technique can be error prone, and often results in “Death Star” architectures which rely on chained calls to enforce application invariants. These architectures become more complicated over time, and are difficult to modify and extend, and often don't correctly handle all failure scenarios.

In this talk I propose a new solution for this problem, Distributed Sagas, a protocol for coordinating requests among multiple micro services, while ensuring application invariants.

Caitie McCaffrey

May 19, 2017
Tweet

More Decks by Caitie McCaffrey

Other Decks in Technology

Transcript

  1. 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
  2. 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.”
  3. 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
  4. 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
  5. Distributed Saga Guarantee Book Hotel Book Car Book Flight Charge

    Money All requests were completed successfully
  6. 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
  7. 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
  8. 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
  9. 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
  10. Start & End Vertices Distributed Saga Start Saga End Saga

    Car Flight Hotel Payment Start Saga End Saga
  11. Car Flight Hotel Payment Start Saga End Saga SEC Saga

    Log Done Start Saga Book Trip Request
  12. Car Flight Hotel Payment Start Saga End Saga Saga Log

    SEC Book Hotel Request Start Saga Start Hotel
  13. Car Flight Hotel Payment Start Saga End Saga Saga Log

    SEC Book Hotel Response Start Saga Start Hotel
  14. Car Flight Hotel Payment Start Saga End Saga Saga Log

    SEC End Hotel Start Saga Start Hotel
  15. Car Flight Hotel Payment Start Saga End Saga Saga Log

    SEC Done Start Saga Start Hotel End Hotel
  16. Car Flight Hotel Payment Start Saga End Saga Saga Log

    SEC Start Car Start Saga Start Hotel End Hotel
  17. Car Flight Hotel Payment Start Saga End Saga Saga Log

    SEC Done Book Car Request Start Saga Start Hotel End Hotel Start Car
  18. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car Book Car Response End Car
  19. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car Done End Car
  20. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car Start Flight End Car
  21. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car Done End Car Start Flight Book Flight Request
  22. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car End Car Start Flight Book Flight Response End Flight
  23. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car End Car Start Flight Done End Flight
  24. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car End Car Start Flight Start Payment End Flight
  25. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car End Car Start Flight Done End Flight Start Payment Payment Request
  26. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car End Car Start Flight End Payment End Flight Start Payment Payment Response
  27. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car End Car Start Flight End Flight Start Payment End Payment Done
  28. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car End Car Start Flight End Flight Start Payment End Payment End Saga
  29. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car End Car Start Flight End Flight Start Payment End Payment Done End Saga
  30. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Start Car End Car Start Flight End Flight Start Payment End Payment End Saga
  31. Car Flight Hotel Payment Start Saga End Saga Saga Log

    SEC Book Car Request Start Saga Start Hotel End Hotel Start Car Start Flight
  32. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Book Car Response Abort Car Start Car Start Flight
  33. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Done Start Car Start Flight Abort Car
  34. Car Flight Hotel Payment Start Saga End Saga Saga Log

    Start Saga SEC Start Hotel End Hotel Done Start Car Start Flight Abort Car Rollback Recovery
  35. Car Flight Hotel Payment End Comp Saga Start Comp Saga

    Saga Log Start Saga SEC Start Hotel End Hotel Start Car Start Flight Abort Car
  36. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Start Comp Saga End Comp Saga
  37. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Payment Log Entries? Start Car Start Flight Abort Car Start Comp Saga End Comp Saga
  38. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel { } Start Car Start Flight Abort Car Start Comp Saga End Comp Saga
  39. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Car Log Entries? Start Comp Saga End Comp Saga
  40. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car { Start, Abort } Start Comp Saga End Comp Saga
  41. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Hotel Log Entries? Start Comp Saga End Comp Saga
  42. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car { Start, End } Start Comp Saga End Comp Saga
  43. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car { Start, End } Cancel Hotel Request Start Comp Saga End Comp Saga
  44. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Cancel Hotel Response Comp Hotel Start Comp Saga End Comp Saga
  45. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Done Comp Hotel Start Comp Saga End Comp Saga
  46. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Comp Hotel Flight Log Entries? Start Comp Saga End Comp Saga
  47. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Comp Hotel { Start } Start Comp Saga End Comp Saga
  48. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Comp Hotel { Start } Book Flight Request Start Comp Saga End Comp Saga
  49. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Comp Hotel End Flight Book Flight Response Start Comp Saga End Comp Saga
  50. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Comp Hotel Done Cancel Flight Request End Flight Start Comp Saga End Comp Saga
  51. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Comp Hotel Comp Flight Cancel Flight Response Start Comp Saga End Comp Saga End Flight
  52. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Comp Hotel Done Comp Flight Start Comp Saga End Comp Saga End Flight Comp Flight
  53. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Comp Hotel End Saga Start Comp Saga End Comp Saga Comp Flight End Flight Comp Flight
  54. Car Flight Hotel Payment Saga Log Start Saga SEC Start

    Hotel End Hotel Start Car Start Flight Abort Car Comp Hotel Done End Saga Start Comp Saga End Comp Saga Comp Flight End Flight Comp Flight
  55. 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
  56. with Distributed Sagas Isolation of Complex Code Fron Tr Complex

    Code Lives Everywhere Front SEC Saga Log Complex Code Lives Here Complex Code Lives Here
  57. Fron Tr with Distributed Sagas Modular Services Front SEC Saga

    Log Only Flight Booking Flight Booking & Feral Concurrency Control Mechanisms
  58. Fron Tr with Distributed Sagas Service Composition Front SEC Saga

    Log Just Add A New Saga! New Service & Feral Concurrency Control Mechanisms