SOLID & Design Patterns Interview Question #92

What is the Timeout Pattern?

DDD Boundaries, Resilience, Caching & Practical ASP.NET Core Design Mid-Level Intermediate

Quick Interview Answer

The Timeout Pattern limits how long an application waits for an operation or dependency. Without a timeout, slow downstream services can consume threads, connections, and request capacity for too long.

Detailed Explanation

The Timeout Pattern limits how long an application waits for an operation or dependency. Without a timeout, slow downstream services can consume threads, connections, and request capacity for too long.

Timeout values should reflect the operation's expected latency and end-to-end request budget. Cancellation should be propagated when possible so unnecessary work stops throughout the call chain.

Code Example

using var cts =
    new CancellationTokenSource(
        TimeSpan.FromSeconds(5));

await service.CallAsync(cts.Token);