Spring / Spring gRPC Interview Questions
How do you propagate contextual data such as a request ID or authenticated user through a gRPC call in Spring?
gRPC provides its own io.grpc.Context API, which behaves like a ThreadLocal but is designed to propagate correctly across the async, callback-driven code paths that streaming calls use (where a plain ThreadLocal would often lose its value across thread hops).
The typical pattern is: an interceptor reads a value out of incoming Metadata (for example an x-request-id header), stores it under a well-known Context.Key, and attaches that to the current context before invoking the service method. Downstream code - including code in nested outgoing calls made from within that method - can then retrieve it via Context.current(), without it being passed explicitly through every method signature.
More Related questions...