2

Recently I'm studying Saga pattern, but I'm struggling to imagine how it will work in real system. Standard example is making an order, which consist of reserving flight, hotel and a car.

We can assume that we have following services:

  • ordering service
  • flights booking service
  • hotels booking service
  • cars booking service
  • payments service

All works nice when order is created, and sends commands (messages via message bus) to respective services (e.g. ReserveMoney, BookFlight, BookHotel, BookCar) and this services returns either success or failure messages within reasonable time. If all messages were successful, saga completes with SUCCESS state, otherwise it FAILS and performs compensating transactions.

I see following problem in the above (yet commonly accepted example):

When one service (e.g. car booking) is down - then saga will receive message from car service after some unknown time. From UX perspective I'd like to inform customer, that order failed no more than within 30-60seconds. Such thing will not happen when saga is based on incoming messages (because saga won't be aware that already 10 minutes passed and cars service is kind of down, because we haven't got any message from it yet).

My idea is to create a background process that will select an PENDING saga from the DB, and try to perform next saga step.

  • if step succeed or fail, it will save saga state in DB, and finish this single saga iteration.
  • if step failed more than possible retry count, than saga will be marked as FAILING.

When next background process picks the PENDING or FAILING saga it will again try to perform saga's next step (or next compensating transaction in case of FAILING).

What am I missing in understanding Saga pattern?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.