Spring Boot Interview Question - @Async Broke Our Audit Logs
Your request remembers everything. @Async remembers nothing
Context
A payment service stores request metadata in MDC so every log line contains the request information.
The controller logs look correct:
requestId=8fa92
merchantId=paypal-123
userId=surajBut every log produced inside sendReceipt() shows:
requestId=null
merchantId=null
userId=null🚀 Level up your Java & Spring Boot skills.
Join 8100+ developers and get weekly, no-fluff content featuring practical coding tips, real-world backend insights, and interview questions based on production scenarios.
Founding Member Offer: Lock in founding member price at $50/year (~$4/month) for life. Limited spot left.
Testimonials
Why did the audit context disappear?
MDC uses ThreadLocal
Most logging frameworks store MDC using ThreadLocal. The values belong only to the current thread.
@Async executes on another thread
The executor picks another thread from its pool. That thread has a completely different ThreadLocal map.
Request Thread -> Async Executor ThreadHence MDC.get("requestId") returns null
ThreadLocal values are NOT inherited
Unlike method arguments, ThreadLocal state is never copied automatically. Even if the thread comes from the same executor every time, the context is not transferred.
How would you fix it without changing every
@Asyncmethod in the application?






