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.
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:
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:
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:
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.
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.
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:
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.
So, what are the different and similar features between microservices and orchestration? Let us briefly summarise this:
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.
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:
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.