Spring MVC and Async
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Spring MVC supports asynchronous request handling, which helps web applications stay responsive when work takes longer than a normal request cycle. Teams often mix up MVC async request processing and @Async background execution, but they solve different parts of the problem. This guide shows how they fit together and how to configure them safely.
Core Topic Sections
Two async models in Spring web applications
Spring provides two related but distinct patterns:
- MVC async request processing with
Callable,DeferredResult, orWebAsyncTask. - Method-level async execution with
@Asyncon service methods.
MVC async frees the request thread while waiting for work. @Async runs work on a task executor. In many systems you use both.
MVC async with Callable
A controller can return Callable so the servlet container thread is released quickly, and response generation resumes when callable completes.
This pattern is simple and works well for bounded tasks.
MVC async with DeferredResult
DeferredResult is useful when completion is driven by another component or callback.
This gives explicit timeout and lifecycle hooks.
@Async service layer execution
Use @Async for background business logic that should run on a managed executor.
Controller can return CompletableFuture directly in modern Spring versions, which integrates cleanly with async response handling.
Configure executor and async support
Default executors are not ideal for production. Configure thread pool sizes and queue limits explicitly.
Tune values with load tests rather than guesses.
Timeouts, errors, and observability
Async code fails differently from synchronous handlers. Always define:
- Request timeout behavior.
- Exception mapping for async failures.
- Metrics for queue depth and execution time.
- Correlation identifiers in logs.
Without these controls, async endpoints become hard to debug under load.
Avoid blocking mistakes
Common anti-pattern is marking controller async while still doing blocking network calls on a small thread pool. Async architecture only helps when the full flow is designed for concurrency.
Practical rules:
- Keep blocking operations in appropriately sized worker pools.
- Avoid sharing tiny executors across unrelated workloads.
- Apply backpressure and reject policies for overload protection.
Testing strategy
Test async behavior, not only response body:
- Verify timeout responses.
- Verify error mapping from background failures.
- Verify that thread pools do not exhaust in load tests.
Include integration tests with realistic delays to validate operational behavior.
Common Pitfalls
- Assuming
@Asyncalone makes an MVC endpoint non-blocking end to end. - Using default executors in production without capacity planning.
- Missing timeout handling and leaving requests hanging.
- Ignoring async exception mapping and losing useful error diagnostics.
- Running blocking work in undersized pools and creating thread starvation.
Summary
- Spring MVC async request handling and
@Asyncaddress different layers. - Use
CallableorDeferredResultto free request threads. - Use managed executors with explicit sizing for background tasks.
- Define timeout, error, and observability policies early.
- Validate async behavior with integration and load testing.
Related reading
- Spring Non-blocking Rest Send and forget
- Spring reactor executing consumers asynchronously
- Spring Security and Async Authenticated Users mixed up
- SpringBoot Async requests throwing 503 Service Unavailable
- Spring MVC Annotated Controller Interface with PathVariable
- Spring MVC Complex object as GET @RequestParam
- Springboot How to use WebClient instead of RestTemplate for Performing Non blocking and Asynchronous calls
- sql multithreading application select and delete from a table

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.