ASP.NET Core Web API Interview Question #143
What is a timeout and why should external calls have one?
Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced
Quick Interview Answer
A timeout limits how long an operation is allowed to wait before it is treated as failed. Without suitable timeouts, slow downstream dependencies can consume request resources for excessive periods and contribute to cascading failures.
Detailed Explanation
A timeout limits how long an operation is allowed to wait before it is treated as failed. Without suitable timeouts, slow downstream dependencies can consume request resources for excessive periods and contribute to cascading failures.
Timeout values should reflect the operation and user experience. Cancellation should also be propagated so abandoned work can stop when possible.
Code Example
builder.Services.AddHttpClient<IPaymentClient, PaymentClient>(client =>
{
client.Timeout = TimeSpan.FromSeconds(10);
});