Company
Date Published
Author
Denis Rosa, Developer Advocate, Couchbase
Word count
897
Language
English
Hacker News points
None

Summary

In the context of distributed transactions, the Command/Orchestration approach is used to address challenges such as complex transactions or cyclic dependencies of events. This approach involves defining a new service that communicates with each participant in a command/reply style, telling them what operation should be performed. The saga pattern orchestrator coordinates the flow needed to execute a transaction, and if anything fails, it coordinates the rollback by sending commands to each participant to undo the previous operation. A standard way to model a saga orchestrator is a State Machine, where each transformation corresponds to a command or message. Rollbacks are easier when an orchestrator is present, as it can coordinate everything. The Command/Orchestration design has benefits such as avoiding cyclic dependencies between services, centralizing the orchestration of distributed transactions, reducing participants' complexity, and making rollbacks easier. However, this approach also has drawbacks, including concentrating too much logic in the orchestrator and increasing infrastructure complexity. To implement a saga with these benefits, it's recommended to create a unique identifier per transaction, add the reply address within the command, use idempotent operations, avoid synchronous communications, and consider using a Request/Response MQ model or direct request to services for immediate response and service availability.