Choreography

Unlike with orchestration, in choreography, each component is tuned to carry out a predefined task in coordination with the others. It is more like a dance group that has been taught to perform predefined steps. Sometime, the dancers perform steps with other dancers or in parallel with other dancers.

Orchestration always represents control from one perspective. This differs from choreography, which is more collaborative and allows each microservice to be involved in the interaction.

In choreography, each service talks to another service after finishing its work or, sometimes, also between its work to trigger or initiate the task in the next service. This communication can happen in a one-to-one, one-to-many, or many-to-many fashion. Like in orchestration, choreography can happen in a synchronous way or asynchronous way. Ideally, in choreography, there is a global protocol on which each service decides to communicate with each other. Choreography is preferred to be used with asynchronous communication. As there is no central service, each component just raises the event when it finishes its task, which makes the services decoupled and independent of each other. Each component will be listening to an event or message raised by another service and reacting to those messages.

In choreography, the services are connected with messages or subscriber channels or topics to observe their environment. With message-based communication, choreography will be very useful. Decoupling, and adding a new service and removing old services is very easy. It saves the system from dependency hell, which can arise in the orchestration pattern. Needless to say, choreography increases the complexity in the system. Each service is producing and consuming messages at run time, so there is no proper way to identify the exact state of any transaction. A service has to have its own implementation to see the current state of the system. This could be a trade-off with this pattern.

No one pattern is better than another here. It is more of a situational call to use any of the patterns mentioned earlier. Sometimes, a mix of these two patterns works in the same system. The event stream for analyzing the big data can use a choreography pattern, and the system inside uses orchestration. Let's move to another angle to see the pattern in the microservice.

From another perspective, the method of data flow and communication between microservices can be categorized into:

  • Synchronous
  • Asynchronous
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset