The microservice architecture is a collection of small services with each service having a specific function. These service modules can’t perform well in isolation and need some kind of medium so that they interact and share data.
This leads us into one question: How to stitch these service modules together?
There are two ways to do it: Microservice Orchestration and Microservice Choreography. We will talk about both in detail.
Microservice Orchestration vs Choreography
What is Microservice Orchestration?
In an orchestra, we have a central man called the “orchestrator”. Therefore, he is responsible for invoking all the sounds.
Similarly, in the microservice orchestration, the orchestrator (central controller) handles all the microservice interactions. It transmits the events and responds to it.
The microservice Orchestration is more like a centralized service. It calls one service and waits for the response before calling the next service. This follows a request/response type paradigm.
Benefits of Microservice Orchestration
- Easy to maintain and manage as we unify the business process at the center.
- In synchronous processing, the flow of the application coordinates efficiently.
Limitations of Microservice Orchestration
- Creating dependency due to coupled services. For example, if service A is down, service B will never be called.
- The orchestrator has the sole responsibility. If it goes down, the processing stops and the application fails.
- We lose visibility since we are not tracking business process.
What is Microservice Choreography?
Choreography is the other way to achieve microservice interaction. In microservice architecture, we want to avoid dependencies. So, that each service can work independently. Choreography solves this issue which was the main challenge in orchestration approach.
Choreography is basically like decentralized way of broadcasting data known as events. The services interested in those events, use it and perform actions. That means every service has a brain of their own and do not require any instructions, as was the case in orchestration approach. This is also known as event-driven architecture or reactive architecture. The services know what to react to, and how to, more like an asynchronous approach.
This asynchronous approach avoids the waiting time which is experienced in orchestration due to request/response type of processing.
Benefits of Microservice Choreography
- Faster processing as no dependency on central controller.
- Easy to add and update. The services can be removed or added anytime from the event stream.
- As the control is distributed, there is no single point failure.
- Works well with agile delivery model, as teams work on certain services rather than on entire application.
- Several patterns can be used. For example, Event sourcing, where events are stored, and it enables event replay. Command query responsibility segregation (CQRS) can separate read and write activities.
Limitations of Microservice Choreography
- Complexity is the concerning issue. Each service is independent to identify the logic and react based on the specific data in the event stream.
- Business process is spread out, making it difficult to maintain, manage the overall process.
- Mindset change is prerequisite in the asynchronous approach.
Most of the times, these approaches don’t work well in the architecture. So, what is the solution in these use cases?
The answer is the Hybrid approach.
Yes, the hybrid approach can solve the problem, if we have a mix of synchronous and asynchronous blocks of activity. In such situations one or more hybrid pattern can add value to the projects.
What is the Hybrid Approach?
Hybrid combines the centralized service (orchestration approach) within the services and the Reactive (choreography approach) is used in between the services, that is, to communicate to other services through events.
In other words, the hybrid approach uses choreography to execute the processed logic with the help of central manager. The manager is responsible for holding up the events in an event store. The manager also communicates with the coordinator (reactive orchestrator) to provide a visual of the events happening in data pipelines.
Hybrid approach like others is two-edged. Let’s discuss.
Benefits of the Hybrid Approach
- Overall flow is distributed. Each service contains its own flow logic.
- Services are decoupled (but to an extent).
Limitations of the Hybrid Approach
- The coordinator is coupled with the services.
- If the coordinator goes down, it impacts the entire system.
In short, all the approaches have its own benefits and trade-offs. As the saying goes “one can’t make eggs without breaking them”.
In a Nutshell
Orchestration and Choreography (Reactive) are rather opposite concepts. The former uses single, centralized approach to execute the decisions, whereas latter gives more freedom to execute those decisions. However, both (hybrid approach) can be used in order to rectify their respective drawbacks. The orchestration provides better visibility and has better control whereas choreography has more reactive bearing. You can choose from microservice orchestration vs choreography according to your business needs and goals.
Learn about the microservice architecture in detail.