Set Request Deadlines: Bound the Total Time a Request Can Use
A request deadline is the point in time after which the caller no longer wants to wait; a timeout is the maximum duration allowed for one operation. For a request that crosses services, set one overall deadline and propagate the remaining time to downstream calls. This reduces work spent after the caller has already given up.
A request deadline is the point in time after which the caller no longer wants to wait; a timeout is the maximum duration allowed for one operation. For a request that crosses services, set one overall deadline and propagate the remaining time to downstream calls. This reduces work spent after the caller has already given up.
Deadline and timeout
A deadline can be calculated by adding a relative duration such as “3 seconds from now” to the start time. If a request passes through a network, queue, processing stages, and downstream services, giving every stage a fresh 3-second timeout can make the total wait much longer than intended. A downstream timeout far shorter than the parent deadline can cause avoidable failures.
For example, if a request has a 3-second total deadline and its first service uses 0.8 seconds, roughly 2.2 seconds remain for the next service. Reserve time for network transit and final response handling instead of assigning all remaining time downstream. These numbers are illustrative; measure latency and user expectations to choose real deadlines.
Propagate the deadline
**Set a realistic limit at the entry point.** Use observed completion times by operation and acceptable user wait. With no deadline, a caller may wait effectively forever; a very long one lets stuck work occupy threads, memory, and connections. An overly short one can fail valid, expensive requests.
**Pass remaining time to child calls.** Do not give every downstream call a fresh full duration; subtract time already spent on the parent request. Protocols that transmit absolute times must account for clock differences. gRPC converts a propagated deadline to a timeout after subtracting elapsed time, reducing clock-skew issues. Check whether propagation is automatic or requires configuration in your language.
**Check whether work is still useful at each stage.** After a queue wait and before expensive computation or a downstream call, compare remaining time with expected work. If too little remains, do not start or fail fast. The caller may already have given up when a late response arrives. Long-running batch work that can checkpoint and resume may need a separate policy for continuing past the request deadline.
**Propagate cancellation downward.** Deadline expiry or user cancellation signals that new work should stop. Connect framework cancellation to application-started tasks, queries, and child RPCs so they observe cancellation and clean up. Shared work or committed side effects need their own safe-stop point and compensation rules.
**Make expiry diagnosable.** Track the overall deadline, time spent at each stage, queue wait, remaining child-call time, and cancellation outcome. Distinguish deadline expiry, server errors, and client cancellation without logging excessive request data.
What to check in gRPC
Without an explicit deadline, a gRPC client may wait indefinitely. After expiry, the caller receives DEADLINE_EXCEEDED and the server call may be cancelled, but the server application is responsible for stopping work it already started. Some gRPC language implementations propagate deadlines automatically; others require configuration. Check the documentation for the language and library version in use.
Verification
Exercise a fast request, a slow queue, a slow dependency, and cancellation just before expiry. Check that remaining time shrinks for downstream calls, cancellation reaches child work, and useless work is cleaned up. Confirm downstream waits do not outlast the parent deadline and retries do not restart the full deadline. No gRPC service or network test was run here.
Sources
[gRPC: Deadlines](https://grpc.io/docs/guides/deadlines/)
[Google SRE Book: Addressing Cascading Failures — Latency and Deadlines](https://sre.google/sre-book/addressing-cascading-failures/)