SAGAs - DistributedTravels/Documentation GitHub Wiki

SAGAs

The whole system has two separate sagas: GetOffers saga and ReserveOffer saga.

GetOffers Saga

The process of getting available offers can be divided into a few steps:

  • setting up saga and initializing first values
  • checking the database for available offers
  • asking hotels and transport services for available rooms and flights (if there were not enough trips in the database)
  • combining received hotels and flights to create trips and saving them to the database (if there were not enough trips in the database)
  • sending back available offers

This saga cannot really fail, as even if there are no offers available it just responds with an empty list. Therefore no rollback is required.

ReserveOffer Saga

This saga is a bit more complicated than the previous one. It's initiated when the ReserveOfferEvent is received and at first checks if the offer with selected requirements is available (by asking hotels and transport services or just hotels service if one of the requirements is that the client has own transport). When it receives positive responses from other services it can enter the TemporarilyReserved state. Otherwise it enters ReservationFailed state. When entering TemporarilyReserved state, the saga schedules a delayed (by one minute) message, goal of which being reservation cancellation. During this state the saga awaits an event with payment information, which it forwards to payments service. After that it awaits the response from that service. If at any point the cancellation event or a negative response from payment is received then the saga enters ReservationFailed state. If a positive response from payment is received the saga enters SuccessfullyBooked state. ReservationFailed and SuccessfullyBooked are both final states. When entering ReservationFailed state, the saga sends reservation cancellation commands to hotels and transport services (to rollback changes). During any state the saga may receive AskForReservationStatusEvent to which it responds with a specific status:

  • before TemporarilyReserved - WAITING_FOR_RESERVATION
  • during TemporarilyReserved - WAITING_FOR_PAYMENT
  • during SuccessfullyBooked - SUCCESSFUL
  • during ReservationFailed - FAILED