Quick revision
The short answer
The request-scoped bean is looked up through RequestContextHolder, which binds the current request to the thread handling it, and an @Async method runs on a different thread from the executor's pool, where no request is bound, so the lookup fails. The clearest fix is to pass the tenant id to the async method as an argument. Alternatively, a TaskDecorator can copy the tenant value into the worker thread before the task and clear it afterwards, and with a context propagation library we can propagate such values the same way everywhere.
What to remember
In this answer, we saw that a request-scoped bean is found through RequestContextHolder, which binds the request to the thread handling it, and that @Async runs the method on a pool thread with nothing bound, so the scope cannot find a request. We fixed it by passing the tenant id as an argument, by a TaskDecorator that copies the plain tenant value to the worker thread and clears it afterwards, or by a context propagation library that does the same consistently for every value and every thread boundary.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The request-scoped bean is looked up through RequestContextHolder, which binds the current request to the thread handling it, and an @Async method runs on a different thread from the executor's pool, where no request is bound, so the lookup fails. The clearest fix is to pass the tenant id to the async method as an argument. Alternatively, a TaskDecorator can copy the tenant value into the worker thread before the task and clear it afterwards, and with a context propagation library we can propagate such values the same way everywhere.
Why this question is asked
Multi-tenant applications almost always carry a tenant id with each request, and a request-scoped bean is a natural place to keep it. Everything works in controllers and services, until someone adds @Async to send a notification in the background and the method starts failing. Interviewers like this debugging question because the answer shows we understand both how web scopes find the current request and how @Async moves work to another thread. In this answer, we will reproduce the failure, follow the call across threads to see why it happens, and then go through three fixes and their trade-offs.
1Reproducing the Failure
A filter reads the tenant from a header and stores it in a request-scoped bean. A controller calls a service, which calls an @Async method.
Notice that the same line works in notifyNow() and fails in notifyLater(). The bean, the proxy and the data are the same. Only the thread is different.
2Why the Async Thread Has No Request
The TenantContext injected into the service is a scoped proxy. Each call on it asks the request scope for the current instance, and the request scope asks RequestContextHolder for the request bound to the current thread. RequestContextHolder keeps that request in a ThreadLocal, a variable with a separate value per thread, which the DispatcherServlet or RequestContextFilter sets when the request starts on a Tomcat thread and clears when it ends.
@Async works through a proxy too. When the controller's thread calls notifyLater(), the async proxy does not run the method; it submits it as a task to a TaskExecutor and returns immediately. The task then runs on a pool thread, for example task-1. That thread never handled the request, so its ThreadLocal is empty, and the request scope has nothing to look in. There is a second, subtler problem: by the time the task runs, the HTTP request may already be finished and its attributes cleaned up, so even copying the request object itself to the worker thread would not be safe.
6 messages in order. Play them, or step through them one at a time.
The request is bound to the Tomcat thread only; the pool thread has none.
3Fix 1: Pass the Tenant Id Explicitly
The simplest fix is to read the tenant on the request thread and pass it to the async method as an argument. The async method then depends only on its parameters, which is easy to read and easy to test.
This is the option to choose first. It makes the dependency on the tenant visible in the method signature, it works with any executor, and it also works when the same method is later called from a Kafka listener or a batch job that has no request at all. The cost is changing signatures, which in a large codebase can be many methods; that cost is also what makes the data flow clear.
4Fix 2: A TaskDecorator That Copies and Clears the Context
When many async methods need the tenant, passing it everywhere becomes noisy. Spring's TaskDecorator lets us wrap every task submitted to an executor. The decorator runs its outer part on the submitting thread, where it can capture values, and returns a Runnable that runs on the worker thread, where it can restore them. Spring Boot applies a TaskDecorator bean to its auto-configured executor, which @Async uses by default. For the decorator to have something to copy, the tenant filter also sets a plain holder, shown below, next to the request-scoped bean, and clears it when the request ends.
Notice that the decorator copies the plain tenant value into a framework-neutral holder, not the request attributes. Copying RequestAttributes to the worker thread is possible but risky, because the request object may be finished and recycled by the servlet container while the task still runs. Notice also the finally block. Pool threads are reused, so if we forgot to clear, the next task on that thread, perhaps for another tenant, would see the wrong tenant id, which in a multi-tenant system is a data leak.
5Fix 3: A Context Propagation Library
When an application has many such values, such as tenant, user, trace id and locale, and many places where work changes threads, such as executors, reactive pipelines and messaging, it is better to propagate them in one consistent way. Micrometer's context-propagation library lets us register a ThreadLocalAccessor for each value once. Spring Framework 6.1 added ContextPropagatingTaskDecorator, which uses that library to capture every registered value on submission and restore it on the worker thread, and Reactor can use the same accessors to move values between threads and the Reactor context.
The benefit is consistency: every boundary propagates the same set of values, and nobody writes a custom decorator per value. The cost is another library and some care that every thread boundary, including custom executors, really goes through the propagation. Whatever we choose, explicit arguments for important business data like the tenant remain the most robust option, because they cannot be lost silently.
6Follow-up questions
Would making RequestContextHolder inheritable fix the problem?
Only in a narrow case. RequestContextFilter and DispatcherServlet can bind the request as an InheritableThreadLocal, which child threads copy when they are created. Pool threads are created once and reused, so they inherit from whichever thread created them, not from the current request. It also keeps the finished request attached to threads. It is not a fix for executors.
How do you test that tenant context never leaks between tasks?
Use an executor with a single thread, submit a task for tenant A and then one for tenant B without context, and assert that the second task sees no tenant. Also run a concurrent test with many tenants and check that every task logs the tenant it was submitted with. These tests catch a missing clear() in the decorator.
Does the same problem happen with virtual threads?
Yes. A virtual thread is still a different thread from the request thread, so ThreadLocal values from the request thread are not visible. Each virtual thread usually runs one task, so leaking between tasks is less likely, but propagation is still needed. Scoped values, final in Java 25, are another way to pass such context to code that runs inside a bounded scope.
7Conclusion
In this answer, we saw that a request-scoped bean is found through RequestContextHolder, which binds the request to the thread handling it, and that @Async runs the method on a pool thread with nothing bound, so the scope cannot find a request. We fixed it by passing the tenant id as an argument, by a TaskDecorator that copies the plain tenant value to the worker thread and clears it afterwards, or by a context propagation library that does the same consistently for every value and every thread boundary.
Open with
The request-scoped bean is a proxy, and every call on it asks the request scope for the current instance. The request scope gets the current request from RequestContextHolder, which keeps it in a ThreadLocal bound to the Tomcat thread handling the request. @Async also works through a proxy: it submits the method as a task to an executor and returns, so the method runs on a pool thread that never saw the request.
Then, if they want more
Its ThreadLocal is empty, and the call fails with "No thread-bound request found", wrapped in a ScopeNotActiveException. The request might even be finished by the time the task runs.
My first fix would be to read the tenant on the request thread and pass it to the async method as a parameter, which makes the dependency visible and also works from Kafka or batch callers.
If many async methods need it, I would register a TaskDecorator that captures the tenant value into a framework-neutral holder on submission, sets it on the worker thread, and always clears it in a finally block, because pool threads are reused and a leaked tenant is a data leak.
For many values, I would use Micrometer context propagation with Spring's ContextPropagatingTaskDecorator, so every thread boundary propagates the same context.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 25, Spring Framework 6
- 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.
- Official documentation
- Spring Framework reference, Core technologies
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 "A request-scoped bean holding the current tenant id works in controllers but fails...": https://scrivio-interview-library.netlify.app/spring-boot/bean-scopes/ac5b9563a2/