ASP.NET Core MVC Interview Question #149

How can an MVC application's performance be measured and diagnosed?

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

Quick Interview Answer

Measure before optimizing. Use structured logs, request timing, application performance monitoring, distributed tracing where appropriate, database query diagnostics, browser network tools, and profiling to identify actual bottlenecks.

Detailed Explanation

Measure before optimizing. Use structured logs, request timing, application performance monitoring, distributed tracing where appropriate, database query diagnostics, browser network tools, and profiling to identify actual bottlenecks.

Important metrics can include request latency, error rate, throughput, database duration, external-service latency, allocation pressure, cache effectiveness, and slow endpoints. Performance decisions should be based on representative production-like workloads rather than assumptions.

Code Example

var stopwatch = Stopwatch.StartNew();

var model = await _service.GetDashboardAsync(token);

_logger.LogInformation(
    "Dashboard loaded in {ElapsedMs} ms",
    stopwatch.ElapsedMilliseconds);

return View(model);