Choreography vs Orchestration in Microservice Architecture

Table of Content

    In modern enterprise applications, multiple components are often distributed across many microservices. Implementing microservice architecture makes it easier to scale and deploy individual services on demand. To build a business workflow in such distributed microservice architecture, the sequence of service and relationship between these services should be defined. The most common patterns for coordinating the services are choreography and orchestration.

    Choreography:
    It represents a distributed approach. Each service involved in choreography works independently and is loosely coupled through shared events. Each service listens to the events they are interested in and performs the corresponding actions on these events. Thus the services manage the workflow among themselves without depending on any orchestrator or having any direct communication between them. This approach focuses on the exchange of messages in business processes. It is an event-driven paradigm.

    unnamed (16)

    Advantages:
    Since the services are not dependent on each other for their execution, failure at any point won’t break the entire system.
    Due to the loosely coupled system, individual services can be added, deleted or scaled up without affecting the entire system. Thus by implementing choreography, the system becomes highly extensible.
    Execution is faster as compared to orchestration since there is no dependency on any central controller.
    With choreographed event-driven architecture, development teams can focus on their individual service rather than the entire system.

    Disadvantages:
    Since the services are distributed, monitoring the workflow becomes challenging.
    Increasing the services can increase the complexity of the system.

    2) Orchestration:
    It represents a single centralized executable component i.e orchestrator that invokes coordination among distributed services. The relationship between all participating services is defined by the orchestrator. It acknowledges all the incoming requests and delegates the request to the respective service. Each service manages its operation and is not aware of the overall workflow. Thus, the orchestrator manages the entire workflow. This framework follows the request-response paradigm.

    unnamed (15)

    Advantages:
    Microservice orchestration helps in automating the business processes. It increases efficiency, productivity, accuracy and reduces the time required to perform the task manually.
    Manual tasks are prone to errors. Orchestrating these tasks helps in reducing manually added errors.
    It is easier to maintain and manage since the entire workflow is defined at a single location.
    Various orchestration tools provide a user interface to monitor the processes. It helps in testing, debugging and solving issues in the workflow.

    Disadvantages:
    Services are tightly coupled. Each service should be successfully completed to move on to the subsequent task. Failure at any point could stop the entire workflow.
    The entire workflow is solely managed by the orchestrator. If the orchestrator goes down, then the entire system fails.
    The Orchestrator directly communicates with each service and waits for its response. Since these interactions take place across the network, its speed may get affected due to network congestion and service unavailability.

    3) Hybrid Approach:
    Both Orchestration and Choreography have certain advantages and disadvantages. In certain situations, implementing a single pattern is not efficient. In such a case, a hybrid approach can be followed. The hybrid approach combines the orchestration approach within the services i.e taking decisions and managing business processes and the choreography approach between the services i.e to communicate with other services through events.

    Advantages of Hybrid Approach:
    Easy to manage and maintain the business process since all the logic is situated at a centralized location.
    Monitoring is easier.
    Services are decoupled to a certain extent.

    Disadvantages:
    Since this approach incorporates a centralized orchestrator, there is a possibility of a single point of failure.
    It can be a more complex solution to implement.
    Workflow Orchestration Tools:
    A very important step in implementing Orchestration would be choosing an orchestration framework that is best suited for your use case. It can help speed up the process. Let us look through a few tools which help in workflow orchestration.
    Kubernetes:
    Developed by Google, Kubernetes is a container orchestration tool. It is usually used as the default solution for automating application deployment, scaling, and management of containerized applications. It’s open-source and provides key features out of the box, including means to scale workloads up and down, service discovery, and sufficient networking capabilities to connect microservices.

    Amazon ECS:
    Amazon Elastic Container Service (ECS) is a container orchestration tool that enables you to run and scale containerized applications on Amazon Web Services (AWS). Developers can run apps on AWS without installing and operating a separate container orchestration software suite.

    Apache Airflow :
    It is an open-source workflow management tool that is used to programmatically write, schedule and monitor workflows. It is based on python and supported by SQLite database. Apache Airflow defines its workflow as code making it
    dynamic, maintainable, versionable, testable and collaborative. Apache airflow provides a User interface that helps in visualizing running pipelines, monitoring processes and troubleshooting the issues when required.

    AWS Step functions :
    It is a serverless orchestration service that helps in coordinating multiple AWS components such as Lambda functions, EC2, SQS etc in a single flexible workflow. Step functions provide a User interface to visualize the state machines at both the design and execution stages.

    Netflix Conductor:
    The conductor is an open-source service created by Netflix which can help in orchestrating the microservices-based process flows in the cloud.

    Orchestration and Choreography are two approaches for microservice operations and one may be more efficient than the other in certain business processes. Orchestration works best when the services are transactional or dependent on others to complete the task. Whereas Choreography works well for services that are asynchronous, execute independently and can be decoupled. Large enterprises might do well by following the hybrid approach where services are choreographed but services having string dependencies have centralized controller-based orchestration. This way independent services won't fail when services they don’t interact with are down but natural dependency is still enforced.

    Topics: Expert Insights