Types of Sagas
Take a look at both types of sagas: choreographed saga and orchestrated saga.
Now, let’s take a look at both types of sagas and how we might use either to handle creating new orders in the MallBots application.
The choreographed saga
In a choreographed saga, each participant knows the role they play. With no coordinator to tell them what to do, each participant listens for the events that signal their turn. The coordination logic is spread out across the components and is not centralized.
Our example from this
The Order Processing module would publish an
OrderCreated
event after creating a new order in the pending state.The Customers module listens for
OrderCreated
events and publishes aCustomerApproved
event after confirming the customer on the order.The Depot module also listens for the
OrderCreated
event and uses the order information to create a shopping list for the bots and publishes aShoppingListCreated
event.The Payments module listens for the
OrderCreated
andCustomerApproved
events and will verify the authorized payment for the order and customer before publishing thePaymentValidated
event.The Depot module will listen for the
PaymentValidated
event to hand the shopping list to a bot before publishing theShoppingInitiated
event.The Order Processing module will be listening for
ShoppingInitiated
to update the order state to “approved.” Then, it will publish a finalOrderApproved
event.
These events and interactions, when mapped out, would look like this:
Get hands-on with 1400+ tech skills courses.