I'm currently studying Saga pattern. Most examples seem to focus on Orchestration Sagas where we have one central saga execution coordinator service that dispatches and receives messages/events. Unfortunately information on how to implement Choreography Sagas seem to be lacking a bit.
In domain driven design, we have multiple bounded contexts, ideally, where each bounded context is a self contained microservice. If microservice A wants to communicate with another microservice B we use Integration Events. Integration Events are published and subscribed to using some asynchronous communication - RabbitMQ, Azure Service Bus.
Assuming we want to start some Saga, for example, where we have to run transactions on Order Service and Customer Service - how exactly do services communicate with each other? Is it just regular Integration Events or something entirely different?
The way I see it and given picture below (source), Saga would be executed this way:
- A new order is created. Status is set to "Pending" and OrderSubmittedDomainEvent domain event is emitted.
- Domain event handler receives OrderSubmittedDomainEvent domain event, it then creates and dispatches ReserveCreditIntegrationEvent integration event.
- Customer Service receives ReserveCreditIntegrationEvent integration event.
- It attempts to reserve customer credit.
- If credit is successfully reserved, CustomerCreditReservedDomainEvent domain event is emitted.
- Domain event handler received CustomerCreditReservedDomainEvent domain event, it creates and dispatches CreditReservedIntegrationEvent integration event.
- Order Service receives CreditReservedIntegrationEvent integration event and sets Order Status to "Confirmed".
- saga is completed.
Is this the right approach?