logo

Microservices Saga – Orchestration vs Choreography

Published: September 26, 2023
# DevOps

Microservices architecture has absolutely changed the approach of developers to building large and complex systems reliably. And, over the last few years, they are rapidly gaining popularity. According to the research conducted by Statista in 2021, 85% of companies utilize microservices.

Well, one of the technical goals of building the application is making it scalable and secure, and microservices allow us to do this, simultaneously making the final product fault-tolerant. So, by breaking down applications into smaller, independently deployable services, microservices offer more flexibility and scalability than traditional monolithic architectures. Using this type of architecture, developers can deploy features that prevent cascading failures. Basically, there are 2 most popular approaches for implementation architecture using microservices: orchestration and choreography. And choosing the right one can be challenging. So, in this article, we would like to compare choreography and orchestration microservices architectures and discuss the projects those types of architecture are more suitable for.

Orchestration vs Choreography

mik_1_ac94d9d3c4.png

When it comes to microservices architecture, there are two common approaches to service coordination: orchestration and choreography. The picture above perfectly illustrates the key differences between those two approaches, and we would like to explain to you how each of them works:

Microservices orchestration:

mik_2_f1c7777b37.png

In this approach, a central orchestrator acts as the “brain,” or logic component, that assigns tasks to the microservices and manages and controls their interaction. In this case, the orchestrator is responsible for routing requests, coordinating service interactions, and ensuring that services are invoked in the correct order. Basically, here, the orchestrator is a central point of control and can enforce rules across the entire system. So, what are scenarios when using orchestration is more beneficial? This approach is an excellent decision when:

  • A set of microservices must be guaranteed to be executed in a specified order.
  • Managing the lifecycle of microservices execution, such as starting and stopping them, is essential for you.
  • You would like to have a unified view of the system and make it easier to troubleshoot and make decisions by having centralized control over the interactions between microservices.
  • Your system is complex, with numerous interdependent microservices, and you need to ensure that each service is operating correctly and that all the services are working together in a coordinated manner.

So, if there are complex workflows with thousands of microservices requiring levels of coordination and sync in your project, orchestration is a great choice for you. But keep in mind that each system has its own drawbacks. So, let’s talk more about the disadvantages of orchestration:

Disadvantages:

Not suitable for large projects

The first disadvantage is that the controller needs to communicate directly with each service and, after that- wait for the response of each service. The consequences here are the following: first of all, when the interactions are occurring across the network, invocations may take longer and can be impacted by downstream network and service availability. The second point is that this system can work okay in small projects, but everything can fall apart when we are talking about hundreds or even thousands of microservices. In such a case, you are creating a distributed monolithic application that will be too slow to function well.

Tight coupling

In the orchestration approach, microservices are highly dependent upon each other: basically, when they are synchronous, every service should respond to requests, thus, if a failure occurs - the whole process will be stopped. Moreover, if we are talking about microservices in an enterprise environment, hundreds or even thousands of microservices are attached to a single function. Therefore, this method won’t fulfill the demands of your business.

Reliance on RESTful APIs

Orchestration also relies on RESTful APIs, and the problem that occurs here is that RESTful APIs and orchestration can’t scale. RESTful APIs are usually created as tightly coupled services. This means that using such services increases the tight coupling of the architecture of your application. Moreover, if you would like to build new functionality, remember that it will cost a lot and have a high impact on the API.

Microservices сhoreography:

mik_3_8f56bb6394.png

In this approach, there is no central orchestrator, and the situation is quite the opposite here: each microservice is responsible for its own behavior and coordination with other services. Services communicate with each other through events and messages without the need for a central point of control. Here, each service can react to events as they happen and can trigger events that other services can react to.

To automatically apply this approach and ensure things go smoothly, you can try choreography tools like Kafka, Amazon SQS, and RabbitMQ. They all are Event Brokers, which is the main tool for this approach. A service mesh like Istio and runtime system DAPR is also used for the choreography approach. So, when should you use choreography? This approach is an excellent decision in the following cases:

Avoiding the creation of a single point of failure or bottleneck is important for you. You need microservices to be autonomic and independent. You want to simplify the process of adding or removing services from the system without disrupting the overall flow of communication.

Now, let’s discuss the benefits of choreography that are solving the problems that occur with orchestration:

Advantages:

Loose service coupling for agility and fault tolerance

Well, adding and removing services is much simpler using a choreographed microservices architecture. Basically, here you will only need to connect/disconnect the microservice to the appropriate channel in the event broker. So, using loose service coupling, the existing logic will not fall apart when you add or remove microservices. And this results in less development churn and flux.

Moreover, because of the independence of each service, when one application fails, the whole system will work while the issue is rectified as choreography isolates microservices. Also, it is not required to have a built-in error handling system in case of failure of the network, as this responsibility lies on the event broker.

Faster, more agile development

As clients' requirements are higher every day and the market grows constantly, the speed of development and modifying the app is crucial. So, the development teams are impacted by changes to other services, and it is a common barrier to achieving agility. But, here, choreographed microservices enable development teams to focus on their key services and operate more independently. So, the services are easily shared between teams once they are created. This allows us to save labor, time, and resources.

More consistent, efficient applications

During the creation of microservices with specific functions, you can create a more modular codebase. In this case, each microservice by itself has its business function, and together, microservices perform a business process. Thus, your system will be consistent, and it will be easy to modify and create services because you can reuse your microservices and tap into code that’s already been proven to perform a given function.

Key Differences and Similarities between Choreography and Orchestration

So, what are the different and similar features between microservices and orchestration? Let us briefly summarise this:

mik_4_4073cec697.png

Similarities

Both approaches involve service coordination and communication and can be used to implement complex workflows and business processes and build scalable and maintainable microservices architectures.

Orchestration and Choreography – how to choose the right approach?

When deciding between orchestration and choreography, it's important to consider the specific needs of your project. Here are some of the most important factors to consider:

  1. Complexity: Orchestration can be a better fit for complex workflows that require a high degree of coordination, and choreography would be an excellent choice for simpler workflows that allow for more emergent behavior.
  2. Flexibility: Choreography is considered to be more flexible than orchestration, as it allows for services to evolve and change independently. And the orchestration is not that flexible, as changes to the central orchestrator can have cascading effects on the entire system.
  3. Scalability: Both approaches can be used to build scalable systems, but orchestration may require more effort to scale as the system grows.
  4. Ease of maintenance: Orchestration can be easier to monitor and debug, as there is a central point of control. Choreography can be more difficult to debug because of the more decentralized nature of service interactions.

To conclude, both approaches, orchestration, and choreography, have their pros and cons, and you should choose the right approach based on the needs of your project.

RELATED BLOG ARTICLES

View all Articles