A timeout limits how long a service waits for an operation. In an order workflow, slow Payment or Shipping responses can delay order creation and breach a latency commitment. A client-side timeout lets the call fail rather than wait indefinitely. section 6.1.1 section 2.5.3
For a Go gRPC client call:
- Create a context with context.WithTimeout(parent, duration), or use context.WithDeadline when you have a target time. section 6.1.1
- Pass that context to the generated client method and handle the returned error if the call does not complete in time. section 2.5.3 section 6.1.1
- Call the returned cancellation function when finished; defer cancel() is a concise way to do so. section 2.5.3 section 6.1.1
ctx, cancel := context.WithTimeout(context.Background(),
10 * time.Second)
defer cancel() #1
payment := pb.NewPaymentClient(conn)
result, err := payment.Create(ctx, &CreatePaymentRequest{}) #2
if err != nil {
// handle Payment create an error
}
The Payment client gets ten seconds to complete Create; the same context is passed into the RPC, and cancellation is deferred. section 2.5.3
Pass the context onward when a service calls another service, so the downstream request remains subject to the caller’s time limit. Timeouts complement selective retries: retries can prolong a blocked call, while a deadline bounds the wait. Circuit breakers address repeated failures by temporarily stopping requests to an unhealthy dependency. section 6.1.1 section 6.4








