liveBook · Manning

Deadline

As explained in gRPC Microservices in Go

A deadline is a configured time limit by which an operation must complete.

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

How gRPC Microservices in Go covers it

How deep it goes
Explains Go context creation, cancellation, propagation, and gRPC timeout outcomes without descending into protocol internals.
Examples
Uses one-second Shipping calls, delayed Order and Product handlers, competing endpoints, and DEADLINE_EXCEEDED after a five-second limit.
What it assumes
Assumes generated gRPC service methods and teaches context.Context as the mechanism for deadlines, cancellation, and cross-service information.
What you can do after
Apply Go context.WithDeadline or context.WithTimeout to gRPC calls and handle cancellation or DEADLINE_EXCEEDED.
How it connects
Connects context.Context, timeout, cancellation, gRPC, status codes, and interservice communication.

Also explained in

Compare how 3 books explain deadline →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of gRPC Microservices in Go. The section links point to the parts of the book it draws on.