A saga is a sequence of local transactions, across several services, which maintain their own database. it, therefore, leads to a challenge to keep distributing data states consistently.
There are two ways of coordinating sagas.
- Choreography(Event-based): each local transaction publishes domain events that trigger local transactions in other services.
- Orchestration(Command-based): an orchestrator(object) tells the participants what local transaction to execute.
Choreography:
All services are linked by a message queue. Service A launches a local transaction for A operation and then sends a message to trigger Service B, and then Service B launches a local transaction B for B operation. Service B may send a message back to service A to report Service A the results.
Service A is an initiator of a business flow, which consists of several independent local transactions.
When a local transaction fails, an initiator is informed, and then the implemented local transactions are rolled back.
Orchestration:
Orchestrator service is the centre of all services, and it supervises the entire flow of services to carry a business logic dynamically. If one service fails, then the orchestrator may ask for rolling back implemented distributed local transactions.
No comments:
Post a Comment