Follow a remote procedure call and reason about a result that arrives after the client’s deadline.
Lesson goal
Trace a unary call through a stub and handler, then choose between a resource-based contract and a named operation.
Before you begin — GraphQL.
A profile service exposes a named operation, GetUser. A caller supplies user ID 42 and expects a user record. Remote procedure call (RPC) lets the caller express this action as a function call while a runtime carries the request to the service that performs it.
A stub is a local object or function that exposes the remote method to client code. Calling the stub starts work on the caller’s machine before anything reaches the server.
GetUser with ID 42. Its stub encodes the input as a message.This is a unary call, with one request and one response. A deadline limits how long the caller will wait. If it expires first, the caller can see a failure even when the server finished the operation. gRPC call lifecycle
gRPC is one implementation of RPC. Its usual setup uses Protocol Buffers to describe methods and messages and to encode their fields on the wire. From the same definition, teams can generate client stubs and server interfaces in different programming languages.
syntax = "proto3";
service UserService {
rpc GetUser (GetUserRequest) returns (User);
}
message GetUserRequest {
string id = 1;
}
message User {
string id = 1;
string name = 2;
}Read the method signature from left to right. It accepts one GetUserRequest and returns one User on success. Generated code supplies the message and call machinery. The team still implements the handler that finds the user. gRPC commonly carries calls over HTTP/2 and also supports server streaming, client streaming, and bidirectional streaming. gRPC service definitions
| Client need | One possible interface | Design consequence |
|---|---|---|
| Fetch a user profile through a standard HTTP interface | GET /users/42 | The resource has a URI, and the response can specify HTTP caching rules. |
| Select fields for a profile screen | A GraphQL user query selecting name | The schema defines client choices, and resolvers supply the values. |
| Call a known service operation from multiple languages | A generated GetUser stub | The service definition fixes the input and output types for callers. |
If public web clients need a profile representation they can cache, the first contract fits that access pattern. If internal teams need a named operation with generated interfaces, gRPC offers that tooling. In either case, the service must define what happens when a user is missing or the caller stops waiting.
A CreateUser RPC times out after the handler saves the new record. Can the caller assume the operation had no effect and send a second creation?
The caller knows only that it did not receive a successful result in time. The first creation may have committed. A repeat that must avoid duplicates needs a contract for recognizing the same logical request or looking up its outcome.