9. February 2021 By Jean-François Gonguet
Use the BPM engine from Camunda to implement a microservices architecture
Microservices architectures are a current trend in the transformation of information systems. The primary benefit is the strong decoupling between the implementation of a microservice and its uses. This guarantees more flexibility in terms of the evolution of applications. This decoupling is guaranteed by using event-driven architectures. The major challenge is setting up a mechanism that guarantees interactions between the microservices, which is known as the choreography of services.
The BPM solution from Camunda (most widely known and commonly used) makes it possible to manage the lifecycle of business process instances: this is the orchestration of processes. This article demonstrates how this solution can also make the choreography of microservices possible.
Microservice concepts
In terms of the architecture of information systems, the current strategy employed by numerous companies is to establish an approach based on microservices. This shift took into account many aspects of SOA architecture (service oriented architecture) and can be considered today as ‘SOA 2.0’.
In his book, ‘Building Microservices’, Sam Newman defines microservices as “small, autonomous services that work together”:
- Small because the microservice has a simple scope, is clearly defined and only fulfils one basic function
- Autonomous because the microservice is accessible via an API regardless of the language of implementation
- Work together because intrinsically any service can interact with other ones
Another positive aspect of adopting an architecture based on microservices is its ability to implement CI/CD (continuous integration/continuous delivery) principles due to the weak coupling between the components.
In terms of execution, a microservice issues events when a call to other services is required, these services react to these events and potentially trigger other events themselves. Together, these interactions define the choreography of services.
Basic principles used by Camunda for the choreography of microservices
The structuring element for the choreography of services is the publication of events and their interception with consistency and integrity (no message loss and unique interception of each message).
If each microservice is implemented in the form of a process, modelled using the power of the BPMN standard and controlled within a BPM engine provided by Camunda, for example, it becomes easy to define the following:
- 1 The points of entry for each microservice and which incoming message structure is to be expected
- 2 When and under what conditions an event is to be sent to another service and to send a message that is consistent with the API of the target service
- 3 The waiting times of a given microservice for the expected answers
The following example is a model of two services that highlight these principles:
Implementation architecture
We have previously demonstrated that developing microservices on the basis of the BPM motor from Camunda makes it possible to efficiently exploit the ‘event-driven’ functions of BPMN. The fact that this very model can be easily enhanced by IT teams to become executable guarantees a large amount of flexibility in terms of quickly taking into account changes in the structure of the microservice.
In order for the choreography of services to take place with all the guarantees of integrity and consistency, we rely on two functions that are available in the BPM engine from Camunda:
- Persistence function: all exchanged messages are stored in a database within a transaction defined by the model
- Scheduling function: Camunda ensures that the time constraints defined in the model, such as a waiting period, will be respected at the time of implementation.
Numerous options are available for the implementation of the architecture: using an instance of the BPM engine, deploy the different models of the microservices in it or embed the BPM engine in separate instances and have them communicate via a message bus (message broker, such as AMQ or event broker, such as Kafka).
The following diagram illustrates an implementation architecture based on the second option:
Conclusion
While Camunda’s primary benefit is the automation of business processes, it can also be used in the choreography of microservices. The support of the BPMN 2.0 standard offered by Camunda allows you to benefit from the aspects specific to event-based modelling, which significantly simplifies the implementation and maintenance of microservices.
adesso has a large number of business and technical consultants who share their experiences and expertise within a ‘Community of Practice WorkAutomation’ and are ready to put this expertise to work on your projects. Please contact us for more information.