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:
What is the better place where store the context data (like the correlation-id) and why?
Thank you!
I would not use ThreadLocal or MDC (which is based on thread local) since it will lock you on implementation details if one day you will want to move to an event loop based service (for example using reactor / web-flux).
You can propogate the context yourself in your method inside a Context object that will flow between your layers (from controller to business logic to DAL). The benefit here is that you are very explicit with this & this might be a bit more maintainable code.
You can also considure looking into spring sleuth (that also integrates with zipkin). It is essentially based on MDC at it's core, but it should support reactor as well.