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

Context Propagation Mechanisms

How deadlines travel through RPC frameworks using context objects, headers, and metadata.

Context Propagation Mechanisms

You'll learn: How distributed systems pass deadline and timeout information across service boundaries using structured context objects, headers, and metadata.

Now that we understand what deadline propagation is, let's explore the how—the actual mechanisms that carry deadline information through your system like a relay baton.

The Three Common Mechanisms

1. Context Objects (In-Process)
Languages like Go and Java provide explicit context objects that travel with each request through your application code. In Go, context.Context carries deadlines internally. When you spawn goroutines or call functions, you pass this context along. The runtime automatically checks if the deadline has expired.

2. HTTP Headers (Cross-Service)
When requests cross network boundaries, context becomes serialized metadata. Common headers include:

  • X-Request-Deadline: absolute timestamp (e.g., Unix milliseconds)
  • grpc-timeout: remaining time (e.g., "500m" for 500ms)
  • Custom headers like X-Timeout-Ms

The receiving service reads these headers, creates a new context with the extracted deadline, and continues propagation downstream.

3. RPC Framework Metadata
Frameworks like gRPC have built-in metadata channels. gRPC automatically converts context deadlines into grpc-timeout headers when serializing requests. On the receiving end, it reconstructs a context object with the appropriate deadline before your handler runs.

The Handoff Pattern

Think of it like airport security checkpoints: your boarding pass (context) contains your flight time (deadline). At each checkpoint (service boundary), staff verify you're not late, stamp it, and pass you through. The format changes—physical pass to digital scan—but the deadline information persists.

Key Takeaway: Context propagation uses in-process objects for efficiency within services and serialized headers/metadata to cross network boundaries, ensuring deadlines survive the entire request chain.