A remote procedure call (RPC), also called remote procedure invocation (RPI), lets a client invoke a service operation much like a local method. The client sends a request and expects a timely response; it may block or use a non-blocking architecture. The call still crosses a process boundary, so the remote service’s availability and latency affect the client. section 8.2 section 8.2.1
Typically, client business logic calls a proxy interface that hides the communication protocol. The proxy sends the request to a server adapter, which invokes the service’s business logic and returns the result. REST and gRPC are options for this interaction. section 8.2
Figure 8.4 The client’s business logic invokes an interface that is implemented by an RPI proxy adapter class. The RPI proxy class makes a request to the service. The RPI server adapter class handles the request by invoking the service’s business logic.
The diagram traces a call from client business logic through the proxy and server adapter to the service. section 8.2
Use request/reply when a query or command needs a timely result, but account for its operational costs:
- The familiar call model is straightforward to implement and avoids operating an intermediate message broker. section 8.2.1
- Client and service must be available and responsive together. A failure or high latency can propagate, so clients need partial-failure handling, including circuit breakers. section 8.2.1 section 8.4
- Clients need service discovery to find a service instance. Prefer a deployment platform’s discovery mechanism when it meets the deployment needs; application-level discovery can handle multiple platforms but takes more work. section 8.4
- Consider asynchronous messaging when reducing runtime coupling or supporting interactions beyond request/reply matters more than the simplicity of direct calls. section 8.2.1 section 8.4
An order service with gRPC
An Order Service API can define createOrder, cancelOrder, and reviseOrder as strongly typed methods. The createOrder operation accepts a CreateOrderRequest and returns a CreateOrderReply. Define the API in a Protocol Buffers interface definition, then use the compiler to generate client stubs and server code. The client stub makes the remote call resemble a local invocation; messages travel in Protocol Buffers format over HTTP/2. gRPC also supports streaming RPC. section 8.2.3
Listing 8.1 An excerpt of the gRPC API for the Order Service
package net.chrichardson.ftgo.orderservice_v1;
service OrderService {
rpc createOrder(CreateOrderRequest) returns (CreateOrderReply) {}
rpc cancelOrder(CancelOrderRequest) returns (CancelOrderReply) {}
rpc reviseOrder(ReviseOrderRequest) returns (ReviseOrderReply) {}
...
}
message CreateOrderRequest {
int64 restaurantId = 1;
int64 consumerId = 2;
repeated LineItem lineItems = 3;
...
}
message LineItem {
string menuItemId = 1;
int32 quantity = 2;
}
message CreateOrderReply {
int64 orderId = 1;
}
...
The API excerpt shows the order methods and their typed request and reply messages. section 8.2.3
Plan a fallback where missing data is less important than a usable response. For example, if a Delivery Service is unavailable, an API gateway can return cached delivery data or omit it while still returning useful order information. In Java, an RPI proxy can use Resilience4j directly or, with Spring Boot, through annotated methods. section 8.2.4







