ASP.NET Core Web API Interview Question #149
How can an API improve resilience when a downstream service fails?
Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced
Quick Interview Answer
Use bounded timeouts, cancellation, carefully targeted retries, circuit breakers, fallback behavior where semantically safe, and clear failure responses. Monitor downstream latency and failure rates so reliability problems are visible.
Detailed Explanation
Use bounded timeouts, cancellation, carefully targeted retries, circuit breakers, fallback behavior where semantically safe, and clear failure responses. Monitor downstream latency and failure rates so reliability problems are visible.
Resilience is not simply adding retries. The design must consider idempotency, capacity, dependency criticality, stale-data tolerance, and what the client should do when the dependency is unavailable.
Code Example
try
{
return await _paymentClient.GetStatusAsync(id, token);
}
catch (OperationCanceledException) when (!token.IsCancellationRequested)
{
throw new DownstreamTimeoutException(
"Payment service timed out.");
}