Course contentsShow
← System Design
Lesson 1099 of 1,91928. Timeouts and DeadlinesFree lesson

Timeout Context in Request Headers

Passing timeout information between services using HTTP headers or metadata to coordinate distributed timeout behavior.

Timeout Context in Request Headers

What you'll learn: How services communicate timeout information to each other using HTTP headers or metadata so the entire request chain respects the original deadline.

The Problem

When a client makes a request with a 5-second timeout, it calls Service A, which calls Service B, which calls Service C. Without coordination, Service C might spend 4 seconds processing a request that Service A already gave up on 3 seconds ago—wasting compute resources on abandoned work.

Passing Timeout Context

The solution is to propagate timeout information through the call chain using request headers or metadata. The original caller includes its deadline or remaining time budget in the request, and each downstream service reads and honors it.

Common approaches:

  • X-Timeout-MS header: Remaining milliseconds in the timeout budget
  • X-Deadline header: Absolute timestamp (e.g., Unix milliseconds) when work must complete
  • gRPC context deadlines: Built-in metadata that automatically propagates

Each service in the chain:

  1. Reads the timeout context from the incoming request
  2. Sets its own internal timeout to be less than the remaining budget (leaving buffer for network/processing)
  3. Passes the updated context to any downstream calls

The Coordination Benefit

This prevents the "zombie request" problem where downstream services waste CPU on work the caller has already abandoned. If Service A times out at 5s, Service B (which reads the header) knows to stop processing after 4.5s, and Service C after 4s—everyone coordinates around the same deadline.

Key Takeaway: Timeout context in request headers allows distributed services to coordinate around a shared deadline, preventing wasted work on requests the client has already abandoned.