The gRPC decision framework
Five axes that classify any gRPC call (RPC shape, sync call or stream, deadline and budget, failure class, concurrency model), applied to RoutingService.GetQuote.
Learning objectives
By the end of this chapter you can:
- Classify any gRPC interaction by its RPC shape: unary, server-streaming, client-streaming or bidirectional.
- Decide whether a call should block synchronously or hold a stream open, based on what the interaction costs.
- Carve a deadline as a slice of an inbound requestâs own budget instead of inventing one.
- Tell a retryable status code (
UNAVAILABLE, budget-permittingDEADLINE_EXCEEDED) from a non-retryable one (INVALID_ARGUMENT,NOT_FOUND). - Pick a concurrency model (blocking, reactive, virtual threads or
grpc.aio) by whether a methodâs bottleneck is waiting or computing.
Why this matters
RoutingService.GetQuote is one request and one response in well under a second. TrackingService.WatchShipment opens a connection that stays open for hours, pushing an event whenever a containerâs position changes. RoutingService.RecomputeRoutes starts work that may take minutes and returns an Operation to poll. All three are gRPC methods on the same contract, and they are three different shapes. Treating them as interchangeable is how a service blocks a thread for an hour or polls a stream that never produces a second message.
Five questions say which shape an interaction needs: RPC shape, sync call or stream, deadline and budget, failure class and retryability, and concurrency model. Later chapters reuse these axes by name whenever they weigh a callâs shape, deadline, retries or concurrency.
RPC shape
The first question eliminates the most options: does the interaction produce one response, a sequence of responses, a sequence of requests, or both at once? Protobuf names all four, and the shipping contract uses each for a reason tied to the interaction.
rpc GetQuote(GetQuoteRequest) returns (GetQuoteResponse); // unary
rpc WatchShipment(WatchShipmentRequest) returns (stream WatchShipmentResponse); // server-streaming
rpc ReportPositions(stream ReportPositionsRequest) returns (ReportPositionsResponse); // client-streaming
rpc NegotiateRoute(stream NegotiateRouteRequest) returns (stream NegotiateRouteResponse); // bidirectional
| Method | Shape | Why |
|---|---|---|
RoutingService.GetQuote |
Unary | Pricing is one question with one immediately known answer. A stream would add flow control, ordering and a half-close protocol for nothing |
TrackingService.WatchShipment |
Server-streaming | A shipmentâs location is a sequence of facts over a voyage, and the caller wants each as it happens, not re-asked on a timer |
TrackingService.ReportPositions |
Client-streaming | A telemetry agent hands off many reports and wants one acknowledgment, not a round trip per report |
RoutingService.NegotiateRoute |
Bidirectional | Either side sends proposals when it chooses, which fits a conversation, not a transaction |
Pick the shape first, because the other axes depend on it. A deadline on a unary call bounds one round trip. A deadline on a streaming call bounds how long the stream may stay open, a different number entirely.
Sync call or stream
This axis asks whether the caller blocks for one value or holds a connection open and consumes values as they arrive. A unary call costs one round trip and releases the HTTP/2 stream, buffers and connection state when the response lands. A stream costs something continuous: the server holds state for the connectionâs life, and both sides need a story for a network blip mid-stream.
WatchShipment is worth that cost because polling a tracking endpoint every few seconds for a voyage of weeks wastes far more connections and still delivers events late. RecomputeRoutes is worth neither a blocking call nor a stream: it returns an Operation at once and lets the caller poll or subscribe, decoupling the workâs duration from any connection.
Default to a synchronous unary call, the cheapest shape to run and reason about. Use a stream when the caller needs a sequence over time as it happens, and an async operation when the work is long but nobody watches it live.
Deadline and budget
Every call carries a deadline: the longest an answer is still useful. A GetQuote that completes correctly in eleven seconds is a failure if the booking flow only had three, because the customer has already seen a timeout.
The hard part is dividing a budget across a chain. When the REST booking service accepts POST /bookings/{id}/confirmation, it has a total budget for the HTTP response, say two seconds. That must cover its own processing, the hop to RoutingService.GetQuote and whatever GetQuote spends calling QuoteService.GetQuote. At the REST to gRPC seam the booking service carves a slice of the budget it already has, so a three-hop chain shares one clock instead of three that together outlast the callerâs patience. Name the deadline as a fraction of the budget you were given.
A deadline thatâs too tight fails calls that would have succeeded. One thatâs too loose lets a slow dependency hold the chain hostage. Size the slice from what the downstream call costs under normal load.
Failure class and retryability
Treating every failure alike retries a bug into a storm or abandons a problem that would have cleared in a second. Status codes let a caller tell them apart without parsing an error string.
| Code | Retry? | Why |
|---|---|---|
UNAVAILABLE |
Yes, with backoff | The server or network couldnât be reached now; often transient |
DEADLINE_EXCEEDED |
Only if idempotent and budget remains | Retrying a non-idempotent call that partly executed risks doing the work twice |
RESOURCE_EXHAUSTED |
Back off, donât resend at once | The server is shedding load, and an immediate resend adds pressure |
INVALID_ARGUMENT |
No | The request is malformed and fails the same way again |
NOT_FOUND, ALREADY_EXISTS |
No | They describe the state of the world, not a glitch reaching it |
FAILED_PRECONDITION, PERMISSION_DENIED |
No | Something has to change first |
GetQuote is a pure read, safe to retry on UNAVAILABLE or DEADLINE_EXCEEDED with no idempotency bookkeeping. RecomputeRoutes starts work, and a blind retry risks two recomputations, so it needs an idempotency key and a status check against the Operation.
Concurrency model
The last axis concerns the server: how a method called many times concurrently runs without blocking on I/O it neednât block on, or spawning more threads than the machine can schedule. The right model follows the work, not a house default.
| Stack | Model | Fits |
|---|---|---|
| Quarkus | Blocking, one thread per call | Simplest; fine while the pool is sized for load, a liability once a downstream like QuoteService.GetQuote is slow |
| Quarkus | Reactive (Mutiny, Vert.x event loop) | Never blocks a thread on I/O, at the cost of differently written code |
| Quarkus | Virtual threads | Blocking style, with thousands multiplexed over a few OS threads; suits I/O-bound fan-out |
| Python | grpcio on a thread pool |
Real concurrency for I/O-bound work, since threads release the GIL on a socket wait; no gain beyond core count for CPU-bound work |
| Python | grpc.aio |
Many concurrent calls on one thread, as long as none block in-line |
Real computation, such as scoring route candidates against live capacity, needs a worker pool regardless, because no async or virtual-thread trick makes CPU-bound work faster by waiting less. The question is whether a methodâs bottleneck is waiting or computing.
The cross-protocol question
The booking serviceâs choice to call GetQuote over gRPC applies the first three axes. The shape is a single question with a single answer, so no stream. The booking service wants to block until it has a price. It has a budget to slice for the outbound call. A unary, blocking, tightly bounded request between two services one organization deploys together is what gRPCâs binary framing and generated stubs are for. A call serving a diverse external client population that needs caching and loose versioning lands on REST.
The contrast generalizes. gRPC, REST over HTTP/2 and WebSockets all move data between two parties and differ in whatâs built in.
| Protocol | Built in |
|---|---|
| gRPC | Generated stubs, a deadline on every call, a canonical status-code vocabulary |
| REST over HTTP/2 | A cacheable contract any browser or proxy speaks; no call semantics |
| WebSocket | A full-duplex byte stream; no deadlines, status codes or generated contract |
A streaming interaction like WatchShipment could run on any of the three. The choice turns on how much of gRPCâs machinery it needs against how much client diversity it must serve.
A worked decision: RoutingService.GetQuote
- Shape. One origin, destination and cargo manifest in; one
Moneyand oneRouteout. Unary. - Sync or stream. Nothing to consume incrementally, and the booking service needs the quote before it proceeds. Synchronous.
- Deadline. The REST request has a couple of seconds, and
GetQuotesits ahead of a second hop intoQuoteService. That leaves it a few hundred milliseconds, so a slow downstream lookup fails fast. - Failure class. No writes, so
UNAVAILABLEand budget-permittingDEADLINE_EXCEEDEDare safe to retry.INVALID_ARGUMENT(a malformedLocation, an empty cargo list) never is. - Concurrency. The work is the round trip to
QuoteService, so it is I/O-bound on both stacks: virtual threads on Quarkus,grpc.aioon Python, neither pinning a thread for the wait.
Decision
RoutingService.GetQuote is unary and synchronous: one question, one answer, and the caller needs the price before it can proceed. Its deadline is a tight slice of the booking service's request budget, propagated rather than invented, because a second hop into QuoteService follows. UNAVAILABLE and budget-permitting DEADLINE_EXCEEDED are safe to retry because the call is a pure read; INVALID_ARGUMENT never is. The work is I/O-bound, so it runs on virtual threads (Quarkus) or grpc.aio (Python) instead of a thread-per-call model sized for compute it doesn't do.
đ€ Explore with your agent
âOpen contracts/proto/shipping/tracking/v1/tracking.proto and contracts/proto/shipping/routing/v1/routing.proto. For TrackingService.WatchShipment, TrackingService.ReportPositions and RoutingService.RecomputeRoutes, apply the five axes (RPC shape, sync or stream, deadline slice of a two-second booking budget, retryable status codes, concurrency model) and write a Decision callout for each in the format of the GetQuote one: only a sequence over time becomes a stream, and a call that starts work gets an idempotency key before it is retried.â
Check: each answer names its RPC shape as declared in the proto (server-streaming, client-streaming, unary returning an Operation) and says whether a retry is safe.
For deeper coverage
- Sam Newman, Building Microservices, 2nd ed. (OâReilly): deadline budgets and failure classification across a chain of inter-service calls.
- HĂŒseyin Babal, gRPC Microservices in Go (Packt): concurrency and performance trade-offs behind the four RPC shapes.
- grpc.io: Status codes and their use: the canonical retryability reference behind the failure-class axis.
- Cloud Native Design Patterns, the API Error Handling appendix, for the same stable-code and retryable-flag error contract applied across REST, gRPC, Kafka and GraphQL.