What is a gRPC unary RPC? Design an operation with one request and one response
A gRPC unary RPC is a call in which the client sends one request message and the server returns one response message. It fits a bounded lookup or command, and a .proto declaration such as rpc Method(Request) returns (Response); expresses that shape. One response does not make a network call behave like an immediate local function or make automatic retries safe. Design a realistic deadline, gRPC status handling, and possible duplicate execution together.
A gRPC unary RPC is a call in which the client sends one request message and the server returns one response message. It fits a bounded lookup or command, and a .proto declaration such as rpc Method(Request) returns (Response); expresses that shape. One response does not make a network call behave like an immediate local function or make automatic retries safe. Design a realistic deadline, gRPC status handling, and possible duplicate execution together.
Unary call lifecycle
The caller invokes a method on a generated client stub and supplies a request message. gRPC handles serialization and network transport; the server implementation receives the request, performs the work, and returns a response with a final status. On success, the client receives the response and OK status. On failure, it receives a failure status and optional details instead. Because gRPC uses HTTP/2, do not judge call success from the HTTP response code alone; inspect the final gRPC status.
syntax = "proto3";
service Catalog {
rpc GetItem(GetItemRequest) returns (Item);
}
message GetItemRequest {
string item_id = 1;
}
message Item {
string item_id = 1;
string name = 2;
}This illustrative contract looks up one item. GetItem is a remote call across a network boundary. The .proto defines method and message shapes, but does not determine storage access, authentication, detailed error policy, or a response latency target.
Include deadlines and cancellation in the call contract
A gRPC client may not set a deadline by default. In that case it can wait effectively forever and hold server resources for too long. Clients should set a realistic deadline based on network latency and server processing time. Derive the value from the system and validate it under representative load; there is no universal duration. When the deadline passes, the client typically ends the call with DEADLINE_EXCEEDED.
The server should also observe deadlines and cancellation, then stop unnecessary work and downstream calls started for that RPC. Propagating the remaining time budget to downstream RPCs helps each service avoid outliving the original call. Even after the client receives a failure, the server may already have completed the operation. Cancellation does not automatically roll back changes already made.
Status codes and retry safety
gRPC status describes the call outcome. For example, an invalid request can use INVALID_ARGUMENT, invalid credentials can use UNAUTHENTICATED, and temporary unavailability can use UNAVAILABLE. Choose a status based on what the client should do next. UNAVAILABLE may indicate a transient failure for which the same call can be retried, but it does not make a non-idempotent command safe to repeat.
When a client sees a deadline or connection failure, it may not know whether the server processed a command. For state-changing unary methods such as decrementing inventory or creating an order, include a request ID or idempotency key in the contract and design atomic duplicate detection on the server. Bound retry policies by status, maximum attempts, and backoff, and monitor retry storms. gRPC libraries can also perform limited transparent retries depending on whether the server application saw the request, so correctness must not rely on the handler running only once.
Choose unary or streaming
Unary RPC has one message in each direction, which makes the unit of work clear and lets the call finish with one result. Server streaming returns multiple responses to one request; client streaming sends multiple requests before one response; bidirectional streaming lets both sides send message sequences. If the result can be produced as one response, unary is simpler. Use streaming when the real data flow continues over time or requires multiple messages within one call.
Implementation checklist
Confirm that one request and one result represent one business operation; do not force a large dataset or many pages into one response.
Document request and response messages, field meaning, status codes, and which error details may be exposed.
Set a client deadline and stop long-running work and downstream RPCs when the server observes cancellation.
Design retry safety, an idempotency key, or duplicate request ID for state-changing commands.
Record final gRPC status rather than just HTTP status; observe latency, failures by status, and retry counts.
Compare with streaming only when multiple messages or a two-way flow are required.
Unary RPC is gRPC's simplest call shape, but the call still crosses a network boundary. A predictable API defines not only the number of request and response messages, but also deadlines, cancellation, final status, and duplicate effects after retries.
Sources
[gRPC core concepts and RPC lifecycle](https://grpc.io/docs/what-is-grpc/core-concepts/)
[gRPC deadlines guide](https://grpc.io/docs/guides/deadlines/)
[gRPC error handling and status codes](https://grpc.io/docs/guides/error/)
[gRPC retry guide](https://grpc.io/docs/guides/retry/)