Suppose the sample scenario in which there's a Microservice X that have to call a Microservice Y. The need is to correlate subsequent calls with a Correlation-ID. Micoservices are Java (Spring Boot) based and expose REST and GRPC apis:
- "X ms" is called passing the Correlation-Id into the header.
- An interceptor in the "X ms" intercept the request and put "somewhere" (Ex. for JAVA in the MDC) the Correlation-Id
- The "X ms" Controller is triggered and delegate the execution of the business logic to a Service class method in the Business Layer.
- The Service class method does some stuff and call "Y ms" by loading the Correlation-Id from "somewhere"
What is the better place where store the context data (like the correlation-id) and why?
- Design methods with specific signatures in order to pass Context data between internal methods.
- Use the MDC.
- Use the ThreadLocal.
- Inject RequestContext where needed (for REST) or use Context (GRPC)
- Other
Thank you!
