Both Orchestration and Choreography are used for Inter Service Communication (ISC) in microservices.
Example use case - When an order is completed, an invoice should be generated for the order items.
Orchestration:
- One central service controls entire business transactions
- Its ideal for synchronous Inter Service Communication
- Tightly coupled - All the integration logic exists in a single Orchestration service (Often called as God object)
- Easier to Rollback business transaction
Solution: OrderOrchestration service to invoke OrderService.CompleteOrder() first, followed by Invoiceservice.GenerateInvoice(). Here entire integration logic present at the OrderOrchestrationService.
Choreography
- Suited for asynchronous Inter Service Communication
- Loosely coupled
- This is implemented using event based architecture (Example: Apache Kafka/Azure Event Hub). Microservices can be configured as both publisher and subscriber of events.
- Harder to Rollback business transactions
Solution - Order Microservice can publish an OrderCompleted event to
Event Hub. An Invoice Microservice can be subscribed to this event and
can generate invoice based on the subscribed events.
No comments:
Post a Comment