← Back to microservices patterns map
⏱️
Microservices Pattern

Timeout Pattern

Never wait forever for an outgoing call.

timeout

Detailed Description

Timeouts cap how long resources are tied up waiting for dependencies.

Set timeouts based on real latency data and overall request budget.

Visual Diagram

Timeout Configuration
  connect_timeout:  2s  (TCP handshake)
  request_timeout:  5s  (full response)
  read_timeout:     3s  (each read chunk)

  ServiceA → calls ServiceB
           → no response in 5s
           → TimeoutException thrown
           → return fallback / 503
  Without timeout: thread hangs forever

Tradeoffs

Pros

Predictable behavior, frees stuck work

Cons

Too short causes false failures

Examples: fetch AbortController, axios timeout, gRPC deadline