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

HTTP Header-Based Propagation

Implementing deadline propagation in REST APIs using custom headers and timestamp arithmetic.

HTTP Header-Based Propagation

You'll learn: How to propagate deadlines across REST API calls using custom HTTP headers and timestamp arithmetic to maintain timeout budgets in multi-service chains.

The Core Idea

While gRPC has built-in deadline propagation, REST APIs need a manual approach. You propagate deadlines by including a custom HTTP header (like X-Request-Deadline or Request-Timeout) that carries either an absolute timestamp (when the entire request must complete) or a relative duration (milliseconds remaining).

When Service A calls Service B, it:

  1. Calculates how much time remains in its own deadline
  2. Subtracts processing time already consumed
  3. Passes the remaining budget to Service B in a header
  4. Service B reads this header and enforces the deadline locally

Timestamp Arithmetic Approach

Absolute deadline (recommended):

X-Request-Deadline: 2024-12-14T10:45:32.500Z

Service B receives this header, compares it against its current time, and knows exactly how long it has. This approach avoids clock skew accumulation across hops—each service measures against its own clock from the same absolute target.

Relative timeout (alternative):

Request-Timeout: 1500

Represents 1500ms remaining. Service B must immediately record receipt time and decrement this budget for downstream calls. More prone to drift since each hop adds measurement overhead.

The Analogy

Think of a relay race baton with a countdown timer attached. Each runner (service) checks the timer, runs their leg, then hands off the baton showing how much time remains. The absolute deadline is like having a fixed finish-line clock everyone can see; relative timeout is like each runner maintaining their own stopwatch.

Key Takeaway:
HTTP header-based deadline propagation uses custom headers carrying absolute timestamps or relative timeouts, with each service performing arithmetic to enforce remaining time budgets across REST API chains.