Distributed Sagas: A Protocol for Coordinating Microservices

2020-02-27 211浏览

  • 1.Distributed Sagas A Protocol for Coordinating Microservices
  • 2.Caitie McCaffrey Distributed Systems Engineer @caitie caitiem.com
  • 3.Monoliths Service Service Service
  • 4.Microservices & NoSQL
  • 5.2015
  • 6.2015 “Application-level Mechanisms for maintaining database integrity”
  • 7.Reserve a Hotel Front End
  • 8.Reserve a Hotel Front End Feral Concurrency Control Mechanisms
  • 9.Reserve a Hotel Front End Feral Concurrency Control Mechanisms
  • 10.Reserve a Car Front End
  • 11.Reserve a Flight Front End
  • 12.Trips Front End
  • 13.Trips Front End Trips
  • 14.Trips Front End Trips Feral Concurrency Control Mechanisms
  • 15.Trips Front End Trips Feral Concurrency Control Mechanisms
  • 16.Trips Front End Trips Feral Concurrency Control Mechanisms
  • 17.Architecture Front End Trips
  • 18.Death Star Architectures
  • 19.Can We Do Better than Feral Concurrency Control?
  • 20.2012
  • 21.2012 “Spanner is Google’s scalable, multiversion, globally distributed, and synchronously-replicated database”
  • 22.2015
  • 23.2015 “The biggest barrier…is that consistency mechanisms must integrate across many stateful services”
  • 24.Two Phase Commit
  • 25.2PC:Prepare Front End Propose Book Hotel Prop r a C k o ose Bo Trips Propose Book Flight
  • 26.2PC:Prepare Front End Vote Book Hotel Vo r a C k o te Bo Trips Vote Book Flight
  • 27.2PC:Commit Front End Commit/Abort Book Hotel A / t i Comm r a C k o o B t r o b Trips Commit/Abort Book Flight
  • 28.2PC:Commit Front End Done Done Trips Done
  • 29.2PC:Commit Doesn’t Scale Front End Done Trips •O (N^2) Messages in Dthe worst case one •Coordinator is a Single Point of Failure •Reduced Throughput Done
  • 30.Distributed Sagas A Protocol for Coordinating Microservices
  • 31.1987
  • 32.1987 “Sagas are Long Lived Transactions [in a single relational Database]”
  • 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.”
  • 34.Distributed Sagas A Protocol for Coordinating Microservices
  • 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
  • 38.Distributed Saga Requests
  • 39.Book Car Requests Can Abort
  • 40.Book Car Requests Can Abort
  • 41.Requests Must Be Idempotent Book Car
  • 42.Requests Must Be Idempotent Book Car
  • 43.Requests Must Be Idempotent Book Car
  • 44.Requests Must Be Idempotent Book Car
  • 45.Book Car Requests Must Be Idempotent
  • 46.Book Car Requests Must Be Idempotent Timeout
  • 47.Book Car Requests Must Be Idempotent
  • 48.Book Car Requests Must Be Idempotent
  • 49.Distributed Saga Compensating Requests
  • 50.Compensating Requests Semantically undoes the effect of a request
  • 51.Compensating Requests Cannot Abort Cancel Car
  • 52.Compensating Requests Can Not Abort Cancel Car
  • 53.Compensating Requests Must Be Idempotent Cancel Car
  • 54.Compensating Requests Must Be Commutative with Requests Book Car Cancel Car is the same as Cancel Car Book Car
  • 55.Compensating Requests Must Be Commutative with Requests Book Car
  • 56.Compensating Requests Must Be Commutative with Requests Book Car Timeout
  • 57.Compensating Requests Must Be Commutative with Requests Book Car Book Car
  • 58.Compensating Requests Book Car Book Car Must Be Commutative Cancel Car with Requests
  • 59.Compensating Requests Book Car Book Car Must Be Commutative Cancel Car with Requests
  • 60.Requests Compensating Requests Idempotent Idempotent Can Abort Commutative Can Not Abort
  • 61.Distributed Saga Guarantee All requests were completed successfully Book Hotel Book Car Book Flight Charge Money
  • 62.Distributed Saga Guarantee All requests were completed successfully Book Hotel Book Car Book Flight Charge Money Or a subset of requests and the corresponding compensating requests were executed Book Hotel Book Car Cancel Hotel Cancel Car
  • 63.Distributed Saga Guarantee All requests were completed successfully No Atomicity Book Hotel Book Car Book Flight Charge Money Or a subset of requests and the corresponding compensating requests were executed No Isolation Book Hotel Book Car Cancel Hotel Cancel Car
  • 64.Distributed Saga Guarantee All requests were completed successfully Visible before No Atomicity Book Hotel Book Car Saga Book Flight Completes Charge Money Book Hotel Or a subset of requests and the corresponding compensating requests were executed Book Car No Isolation Book Hotel Book Car Cancel Hotel Cancel Car
  • 65.Distributed Saga Guarantee All requests were completed successfully Book Hotel Book Car Book Flight Charge Money Or a subset of requests and the corresponding compensating requests were executed Book Hotel Book Car Cancel Hotel Cancel Car
  • 66.defining a Distributed Saga
  • 67.Start Saga Distributed Saga Car Hotel Directed Acyclic Graph Payment End Saga Flight
  • 68.Distributed Saga VertexName:HotelRequest:'>Request: