By Surajtikoo．Sep 14, 2021
It is very common in today’s date that organizations would like to create cloud-native solutions which are easy to deploy on any cloud platform. While evolving towards a microservices architecture, the biggest change is that the monolith application has been divided into multiple independent processes(or services), as a result, a method call between software modules now becomes a remote procedure call go through multiple services..
Microservices is an architectural style that structures an application as a collection of small autonomous services, modeled around a Business Domain. For each and every component different services are created in order to separate the responsibility
“In Microservice Architecture, each service is self-contained and Implements a single Business capability”
As per the above architecture, we see we have multiple business services are involved and multiple communication is happening across microservices.
Why APM Tracing?
Let us understand with a simple example. In the above architecture, we have seen multiple microservices. Microservice UI is the front-end Application that basically calls the Mircosservice2 and Mircorservice3, and further, it calls the Database. During the time of failure of any of the microservices or any issues which can occur at runtime, it becomes challenging to trace or find the exact root cause at that moment
In order to overcome this challenge, we need to have some end-to-end traceability solution that will provide more inner insights about the application. Datadog has the capability to provide this tracing with minimum changes in the application.
One of the major challenges in microservices is the ability to debug issues and monitor them. A simple action can trigger a chain of microservice calls and it would be tedious to trace these actions or a particular single request across the invoked microservices. This is because each microservice runs in an environment isolated from other microservices so they don’t share resources such as databases or log files. In addition to that, we might also want to track down why a certain microservice call is taking so much time in a given business flow.
The below pictures depicts the user follows and with the support of trace id we can easily trace a single request in case of any issues.
The correlation identifier(trace id) is a unique identifier attached to each request in architecture.
The real benefits of the correlation identifier pattern come out when used with a distributed logging system.
In this scenario, each component keeps an audit log with the correlation identifier. When an error occurred in a particular component, it is easy to group related transactions and detect the root cause of the problem.
Let us understand APM with a sample example where we will showcase the communication between different microservices and there end to end traceability.
The below picture contains two microservices. Employee Application and Order Application. The Employee Application contains the endpoints (POST/GET/PUT/DELETE). This Application stores & various employees which are stored in the database.
The Order Application contains the endpoints(POST/GET/PUT/DELETE). This application creates various orders for employees. Both the applications are using the in-memory database which is H2.
Employee Application invokes an API call to retrieve the order details of a particular employee.
The below picture depicts the end-to-end traces during the communication between Micorservice1 and Microservice 2.
With the help of a traceid, we can easily trace a single request. For example, A single API request from a user can be traced down from start to the end of the request from start till the end. APM will inject the same traceid in all the connected/consuming API calls which will easily assist to debug in case of any failures.
The below logs are the Employee & Order Application application logs. The employee application is making an API call to the Order Application. The employee application is injecting the same trace id in the order application.
With the use of Datadog APM enablement, we can easily get end-to-end traceability of our Applications and all the desired metrics which is very useful when we are communicating with multiple microservices.
The original article published on Medium.