A deadline is a configured time limit by which an operation must complete. In a microservice call, it prevents a slow dependency such as Shipping or Payment from making the caller wait indefinitely and helps protect latency commitments. section 6.1.1
Go represents deadlines through context.Context. Create one with context.WithDeadline using a target time, or use context.WithTimeout to specify a duration. Both return a derived context and a cancellation function; canceling stops work that is still using that context. section 6.1.1
Use deadlines to control distributed calls:
- Set a one-second limit on a Shipping service request when the response must meet that latency commitment. section 6.1.1
- Reuse the same context across service boundaries so a timeout can propagate from the client through Order to Product. section 6.1.1
- Cancel competing requests after the first useful endpoint response instead of waiting for the remaining endpoints. section 6.1.1
- Recognize gRPC DEADLINE_EXCEEDED when the configured limit expires before the operation finishes; distinguish it from client-initiated CANCELLED. section 5.3.1
Shipping request with a one-second deadline
Create a context with context.WithDeadline(context.Background(), time.Now().Add(1*time.Second)) and pass it to shippingClient.Create. If the call exceeds the limit, handle the returned error rather than waiting for the operation to finish. section 6.1.1


