The service keyword defines RPC (Remote Procedure Call) interfaces. RPC frameworks like gRPC and ConnectRPC use these definitions to generate client and server code.
Services support four types of communication:
- Unary: Simple request-response.
- Streaming: Send or receive sequences of messages in a single call (Client, Server, or Bidirectional).
The plugins covered in Generating Code produce message and enum types. Turning a service into working clients and servers takes a framework-specific plugin on top: gRPC has plugins like protoc-gen-go-grpc, and ConnectRPC has plugins like protoc-gen-connect-go.
Note: Protobuf gives you the language to define these interfaces. The networking protocols and frameworks that implement them are out of scope for this guide.
service UserService { // Unary: One request, one response rpc GetUser(GetUserRequest) returns (User); // Server Stream: One request, many responses rpc ListUsers(ListUsersRequest) returns (stream User); // Bidirectional Stream: Real-time chat rpc Chat(stream Message) returns (stream Message); }
Further Reading
- gRPC
The original Protobuf RPC framework, with implementations for most major languages.
- ConnectRPC
A CNCF RPC framework built on Protobuf services, compatible with gRPC clients and servers. Its origin story is in Connect: A better gRPC.
Next
Generating Code
Turning .proto files into typed APIs with buf generate or protoc: configuring plugins, and using the generated code to build and serialize messages.