Protocol Buffers (Protobuf) defines structured messages and service functions in .proto files, then serializes message data for exchange between services. Its definitions are language- and platform-neutral; generated code lets clients and servers use them in their own languages. section 3.1 section 2.5.1
To connect an Order service to a Payment service over gRPC:
- Define request and response messages, plus a Payment service function that accepts and returns them, in a .proto file. section 2.5.1
- Use protoc to generate client and server stubs. Implement the Payment-side logic, then call it from Order through the generated client stub. section 2.5.1
message CreatePaymentRequest {
int user_id = 1;
float64 price = 2;
}
message CreatePaymentResponse {
int bill_id = 1;
}
service Payment {
RPC Create(CreatePaymentRequest)
returns (CreatePaymentResponse) {}
}
The listing shows how a payment request, a response containing a bill ID, and a service function fit into one interface definition. section 2.5.1
Generated Go structs represent the messages in application code. Marshalling converts a request to bytes for transmission; unmarshalling converts received bytes back into usable data. The binary encoding carries field metadata as well as values. Small field numbers can use less metadata, while larger integer values can require additional bytes. section 2.5.1 section 3.1.2
Compact binary messages suit interservice communication with strict latency or multilanguage requirements. They are not, by themselves, a reason to replace REST: browser support favors REST, and changes to a gRPC message contract must follow rules rather than treating requests as freely editable JSON. section 1.1.1 section 1.2









