System consists of several micro-services and each of them is in charge of it's own context, such as booking, payment, products and notifications.
Let's imagine we have a traveler who is seeking accommodation on website. Accommodation is listed by retrieving information from products micro-service. Traveler found what he wants and decided to make a reservation.
He selects date, number of nights, people etc, and submits a request to booking micro-service. Request contains all payment details and booking details. Here comes the fun part:
- Request creates a reservation record with status
pending
and publishes event,reservation_created
. - Payment service pools for that event, creates a credit card authorization and publishes event
authorization_successfull
with booking ID inside event payload. - Product micro-service pools for
authorization_successful
event and checks if accommodation is really available for the requested period. If everything is ok, accommodation will be marked as occupied for desired period and publishavailability_updated
event. - Booking micro-service will pool for that event and change reservation status to
approved
, which will then publish new event, so notifications micro-service can pool for it, and send necessary emails.
Now, I have several questions:
This looks nice in theory, but am I over-complicating things, or this is a way to go to achieve decoupling?
By going with this approach, I can't inform traveler "Reservation complete" since there is a long running process involved in the background. My guess is that info message should be more like "Reservation requested, you will receive confirmation email shortly, or i should pool one of service endpoints with loading screen, or even use web sockets to send notification back?"