Choreography ¶
Tldr
The goal of this pattern is to have each component of the system participate in the decision-making process about the workflow of a business transaction, instead of relying on a central point of control (Orchestration)
.
Problem¶
In Microservices, a common pattern for communication is to use a centralized service
that acts as the orchestrator. It acknowledges all incoming requests and delegates operations to the respective services. In doing so, it also manages the workflow of the entire business transaction. Each service just completes an operation and is not aware of the overall workflow.
Solution¶
A client request publishes messages to a message queue
. As messages arrive, they are pushed to subscribers, or services, interested in that message. Each subscribed service does their operation as indicated by the message and responds to the message queue with success or failure of the operation.
In case of success, the service can push a message back to the same queue or a different message queue so that another service can continue the workflow if needed. If an operation fails, the message bus can retry that operation.