ASP.NET Core MVC Interview Question #145

How can asynchronous I/O improve MVC application scalability?

Dependency Injection, Services, Error Handling, Logging & Performance Senior Advanced

Quick Interview Answer

Database calls, HTTP requests, file operations, and other I/O spend time waiting for external work. Using asynchronous APIs allows the request thread to return to the thread pool while the operation is waiting, which can improve throughput under concurrent load.

Detailed Explanation

Database calls, HTTP requests, file operations, and other I/O spend time waiting for external work. Using asynchronous APIs allows the request thread to return to the thread pool while the operation is waiting, which can improve throughput under concurrent load.

Async does not make every operation faster and should not be introduced by wrapping ordinary CPU-bound work in Task.Run inside MVC actions. Use naturally asynchronous APIs and await them through the full call chain.

Code Example

public async Task<IActionResult> Index(
    CancellationToken token)
{
    var items = await _service
        .GetAllAsync(token);

    return View(items);
}