ASP.NET Core Web API Interview Question #181
How do you diagnose a slow API endpoint in production?
Senior API Design, Architecture, Scalability & Production Scenarios Senior Advanced
Quick Interview Answer
Use metrics and distributed traces to determine where request time is spent, then correlate with structured logs. Examine database duration and generated SQL, downstream HTTP calls, serialization cost, thread-pool behavior, resource saturation, locks, and cache effectiveness.
Detailed Explanation
Use metrics and distributed traces to determine where request time is spent, then correlate with structured logs. Examine database duration and generated SQL, downstream HTTP calls, serialization cost, thread-pool behavior, resource saturation, locks, and cache effectiveness.
Optimize the measured bottleneck rather than guessing. Compare p50, p95, and p99 latency because averages can hide severe tail latency.
Code Example
// Measure important operations:
using var activity = ActivitySource.StartActivity("LoadProducts");
var products = await _repository.GetAsync(token);
// Record duration/error metrics through the
// application's observability stack.