gRPC
RPC with an Explicit Contract
gRPC lets you describe a service and its messages in a Protocol Buffers file and then generate client and server code for selected languages. The client calls a remote operation through a typed stub instead of manually assembling an HTTP request.
syntax = "proto3";
service UserService {
rpc GetUser (GetUserRequest) returns (UserReply);
}
message GetUserRequest {
int64 id = 1;
}
message UserReply {
int64 id = 1;
string name = 2;
}
The Contract Is Used to Generate Code
From one .proto file, tools create message classes and call interfaces.
This reduces manual serialization code and helps detect incompatible changes earlier.
gRPC commonly transfers binary Protocol Buffers over HTTP/2. Messages are compact, and a persistent connection works well for frequent internal calls between services.
It Is Not Limited to One Request and One Response
Besides a regular unary call, gRPC supports server streaming, client streaming, and bidirectional streaming. This is useful when data naturally arrives as a sequence and creating a separate HTTP request for every element would be wasteful.