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 figurefigure8_4 could be accomplished by publishing the following events into the message broker:

  1. The Order Processing module would publish an OrderCreated event after creating a new order in the pending state.

  2. The Customers module listens for OrderCreated events and publishes a CustomerApproved event after confirming the customer on the order.

  3. The Depot module also listens for the OrderCreated event and uses the order information to create a shopping list for the bots and publishes a ShoppingListCreated event.

  4. The Payments module listens for the OrderCreated and CustomerApproved events and will verify the authorized payment for the order and customer before publishing the PaymentValidated event.

  5. The Depot module will listen for the PaymentValidated event to hand the shopping list to a bot before publishing the ShoppingInitiated event.

  6. The Order Processing module will be listening for ShoppingInitiated to update the order state to “approved.” Then, it will publish a final OrderApproved event.

These events and interactions, when mapped out, would look like this:

Get hands-on with 1400+ tech skills courses.