ASP.NET Core Interview Question #226

How would you diagnose a slow ASP.NET Core endpoint in production?

Senior ASP.NET Core Real-World Scenarios Senior Advanced

Quick Interview Answer

Start with measurements rather than assumptions. Check request latency percentiles, traces, structured logs, CPU, memory, database timings, outgoing HTTP calls, thread-pool behavior, and cache effectiveness. A distributed trace can show whether the time is spent in middleware, application code, the database, or a downstream service.

Detailed Explanation

Start with measurements rather than assumptions. Check request latency percentiles, traces, structured logs, CPU, memory, database timings, outgoing HTTP calls, thread-pool behavior, and cache effectiveness. A distributed trace can show whether the time is spent in middleware, application code, the database, or a downstream service.

Reproduce the problem with representative inputs when possible, inspect generated SQL and query plans for database-heavy endpoints, and profile CPU or allocations if the request is compute-heavy. Optimize the actual bottleneck and compare the result against a baseline.

Code Example

public async Task<IActionResult> Details(int id, CancellationToken ct)
{
    using var activity = _activitySource.StartActivity("ProductDetails");

    var product = await _service.GetAsync(id, ct);
    return product is null ? NotFound() : Ok(product);
}