Scrivio Interview library
DesignPrincipal6 min read · updated 12 November 2026

Observability and security context (trace ids, user identity, tenant) must flow through MVC, WebFlux, virtual threads, messaging and batch jobs across hundreds of services for the next decade. What long-term standard would you set?

I would standardise on open propagation formats, W3C Trace Context and W3C Baggage, at every network and messaging boundary, and on one instrumentation layer supplied by the platform starter, for example Micrometer Observation bridged to OpenTelemetry. Inside services, teams never invent custom ThreadLocal schemes; they rely on libraries that bridge ThreadLocals, Reactor Context and executors. Propagation is tested across hops in CI and traces with missing context raise alerts, while tenant and identity that security depends on stay explicit in APIs and verified tokens rather than only in hidden context.

Why this question is asked

A decision that must last a decade across hundreds of services cannot be tied to one framework, one threading model or one vendor. In ten years the fleet will contain MVC services, WebFlux services, virtual-thread services, Kafka consumers, batch jobs and things we cannot predict. The context that flows through them, trace ids, user identity and tenant, is what lets us observe and secure the whole system. Interviewers ask this at the most senior level to see whether a candidate can separate what must be standardised, the formats at the boundaries, from what should be delegated, the in-process mechanics, and whether they understand where hidden context is dangerous. In this answer, we will separate the boundary from the inside of a service, choose the formats, choose the instrumentation layer, handle in-process propagation for each execution model, keep security context explicit, and make it verifiable.

1Two Problems: Between Services and Inside Them

Context propagation is really two problems. Between services, context travels as headers on HTTP requests, gRPC metadata or message headers, and the only thing that matters is that every sender and receiver agree on the format. Inside a service, context must follow the work as it moves across threads, executors, reactive operators and virtual threads, and the mechanism depends on the execution model.

The long-term standard should be strict about the first and flexible about the second. Formats at boundaries are the contract between hundreds of services and must not change often. In-process mechanics will change with Java and Spring versions, so the standard should name the libraries that handle them and let the platform team upgrade them.

Step throughA layered context standard
  1. Boundary formatsW3C traceparent, tracestate, baggage on HTTP, gRPC, Kafka
  2. Instrumentation layerMicrometer Observation or OpenTelemetry, from the starter
  3. In-process bridgescontext-propagation, Reactor Context, task decorators
  4. Execution modelsMVC, WebFlux, virtual threads, listeners, batch
  5. Security contextverified tokens and explicit tenant parameters

5 layers, from the top down. Step through them one at a time.

The top layer is the contract; the middle layers are delivered and upgraded by the platform.

2Open Formats at Every Boundary

W3C Trace Context defines the traceparent and tracestate headers, which carry the trace id, the parent span id and sampling flags. W3C Baggage defines a baggage header for small key-value pairs that travel with the request, such as a tenant id for observability or a feature flag cohort. Both are open standards supported by OpenTelemetry, Micrometer, cloud load balancers and most vendors, which is exactly why they are the right choice for a decade: they outlive any single library.

The standard also covers messaging. For Kafka, the same headers go into record headers; for batch jobs, a job run starts or continues a trace and writes it into whatever messages it emits. Any new transport the company adopts must define how these headers map onto it before it is approved.

3One Instrumentation Layer From the Platform

Inside services, one instrumentation layer creates spans, records metrics and handles propagation. In the Spring world, Micrometer Observation is the natural choice, because Spring Framework and Boot instrument themselves with it, and it can export through an OpenTelemetry bridge to any backend. A service that is not Spring may use the OpenTelemetry SDK directly, emitting the same formats.

The platform starter supplies this layer: the dependencies, the bridge, the propagation settings, sampling defaults, logging patterns with trace ids, and the auto-configuration for clients and listeners. Teams do not choose or configure it. The benefit over a decade is that the platform can change the exporter, upgrade the bridge or switch vendors by releasing a new starter, without touching application code.

4Inside a Service: No Custom ThreadLocal Schemes

The biggest long-term risk inside services is home-grown context: a team writes a TenantHolder ThreadLocal, sets it in a filter, and reads it deep inside business code. It works in MVC, silently fails in WebFlux after a thread switch, fails again when work moves to an executor, and leaks between requests if someone forgets to clear it. Multiply that by hundreds of services and each threading model change becomes a hunt for hidden ThreadLocals.

So the standard says: context that must cross threads is registered with the bridging libraries, never managed by hand. Micrometer's context-propagation library, with ThreadLocalAccessors registered in its ContextRegistry, bridges ThreadLocals and Reactor Context, and Reactor's automatic propagation restores them around operators. For executors, Spring's ContextPropagatingTaskDecorator applies the same accessors. For virtual threads, a thread per request makes ThreadLocals work again, but child tasks still need the decorator, and Java's scoped values (final in Java 25) are worth adopting in the bridging libraries as they mature. The point is that the bridges evolve while application code stays the same.

How context follows work in each execution model
Execution modelIn-process mechanismSupplied by
Spring MVC, platform threadsThreadLocal per requestMicrometer, Spring
Spring MVC, virtual threadsThreadLocal per virtual threadMicrometer, Spring
WebFluxReactor Context + automatic propagationReactor, context-propagation
Executors and @Asynccontext-propagating task decoratorSpring, context-propagation
Kafka listenersobservation from record headersSpring Kafka
Batch jobsobservation per run or chunkstarter conventions

5Keeping Security Context Explicit

Not all context is equal. A missing trace id makes debugging harder; a wrong tenant id leaks one customer's data to another. Baggage and propagated context are convenient but hidden, and baggage in particular arrives in a header that any caller can set, so it must never be trusted for authorisation.

So identity and tenant follow a different rule where security depends on them. Identity travels as a verified token, such as a JWT validated at each service or a token exchanged for a downstream audience. The tenant used for data access is taken from that verified token or passed as an explicit parameter in the API and method signatures, for example tenantId as an argument to the repository, so that it is visible in code review and cannot be lost on a thread switch. The tenant may also be copied into baggage and logs for observability, but the copy is never the authority.

6Making It Verifiable for Ten Years

A standard that cannot be checked decays. Each service's CI runs propagation tests from the starter's test kit: a request with a known traceparent and baggage goes in, and the test asserts the same values leave on every outgoing HTTP call and Kafka record. In production, the tracing backend reports traces that start at internal services or lack expected baggage, and alerts go to the owning team when the rate rises.

Finally, the standard itself is reviewed every year or two: new transports, new Java features such as scoped values, and new versions of the instrumentation layer. Because the boundary formats are open standards, these reviews change the middle layers, which the platform owns, rather than the contract between services.

7Follow-up questions

Why not put the tenant only in baggage, since it propagates automatically?

Because baggage is not authenticated. Any client can send a baggage header with any tenant, and a service that trusts it for data access has a serious security hole. Baggage is fine for tagging logs and traces; authorisation must use a verified token or an explicit, checked parameter.

Micrometer or OpenTelemetry directly?

For Spring services, Micrometer Observation, because the framework is instrumented with it and it bridges to OpenTelemetry for export. For non-Spring services, the OpenTelemetry SDK. What matters for interoperability is the wire format, W3C, which both use, so the choice inside a service can differ without breaking traces.

What do you do about legacy services that use B3 or custom headers?

Configure the edge and the platform starter to accept both formats during a transition while always emitting W3C, and track the legacy formats on a dashboard. Retire them service by service as they upgrade, with a deadline announced well in advance.

8Conclusion

In this answer, we built a long-term context standard by separating the boundary from the inside of services. At boundaries, W3C Trace Context and Baggage are the fixed contract for HTTP, gRPC and messaging. Inside services, one instrumentation layer from the platform starter handles spans and propagation, and libraries bridge ThreadLocals, Reactor Context, executors and virtual threads instead of custom ThreadLocal schemes. Identity and tenant used for security stay explicit in verified tokens and APIs, and the whole standard is verified by propagation tests in CI and alerts on traces with missing context.

What to say in the interviewAbout 90 seconds aloud

Open with

I would split it into the boundary and the inside of a service. At every boundary, HTTP, gRPC, Kafka and anything new, the standard is open formats: W3C Trace Context for traceparent and tracestate, and W3C Baggage for small propagated values.

Then, if they want more

Those are vendor-neutral and will outlive any library, which matters over ten years. Inside services, one instrumentation layer comes from the platform starter, in Spring that is Micrometer Observation bridged to OpenTelemetry, so the platform can change exporters or vendors by releasing a new starter.

Teams must not invent ThreadLocal schemes; anything that crosses threads is registered with Micrometer's context-propagation library, which bridges ThreadLocals with Reactor Context, executors via a task decorator, and works naturally with virtual threads, and those bridges can adopt things like scoped values later without touching application code.

Security context is different: baggage is unauthenticated, so identity travels as verified tokens and the tenant used for data access comes from the token or an explicit parameter in the API, visible in code. It can be copied into logs, but the copy is not the authority.

Finally I make it verifiable: propagation tests from the starter's test kit in every CI build, alerts on traces that start mid-system or lack context, and a review of the standard every year or two.

About this answer

Last updated
12 November 2026
Versions it names
Java 25
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Observability and security context (trace ids, user identity, tenant) must flow through...": https://scrivio-interview-library.netlify.app/spring-boot/webflux/e089c61b01/