RPC semantics of gRPC
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Google's gRPC framework is designed around the idea that you can define your application's communication protocol in a language-agnostic way and then use autogenerated client-server stubs to do the remote communication. gRPC uses Protocol Buffers (protobuf) as its Interface Definition Language (IDL) to define both the service interface and the structure of the payload messages.
RPC Semantics in gRPC
Remote Procedure Call (RPC) semantics define how functions or procedures in one computer's process can appear to be called within another process, potentially on a different computer. With gRPC, these semantics are expressed using protobufs, and the framework provides several types of RPCs.
Types of RPCs Supported in gRPC:
Unary RPCs
The simplest type of RPC, where the client sends a single request to the server and gets back a single response. It's effectively a single function call.
Example:
Server streaming RPCs
The client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages.
Example:
Client streaming RPCs
The client writes a sequence of messages and sends them to the server, again using a provided stream. Once it has finished writing the messages, it waits for the server to read them and return a response.
Example:
Bidirectional streaming RPCs
Both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client's messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes.
Example:
Deadlines/Timeouts
gRPC allows clients to specify how long they are willing to wait for an RPC to complete before the call is terminated with the error DEADLINE_EXCEEDED. On the server side, the server can query if a particular call is still viable or if too much time has elapsed.
Metadata
gRPC enables both client and server to send additional metadata in the form of key-value pairs, both at the beginning and at the end of a call. This feature is often used for sending authentication tokens or other contextual information.
Error Handling
gRPC has built-in support for conveying error conditions from server to client. In gRPC, both clients and servers can provide a status code and a status message, as well as an optional status details, which can be used to describe the error programmatically.
Security
gRPC has built-in support for Transport Layer Security (TLS) and its predecessor, Secure Sockets Layer (SSL). gRPC users can configure SSL/TLS to authenticate the server and can also configure the client, providing mutual authentication.
Summary Table
| Feature | Description | Example |
| Unary RPC | Simple request-response pattern. | rpc SayHello (HelloRequest) returns (HelloResponse); |
| Server streaming RPC | Client sends a request, gets a stream to read a sequence of messages. | rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse); |
| Client streaming RPC | Client writes a sequence of messages, server returns a single response. | rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse); |
| Bidirectional streaming RPC | Both client and server send a sequence of messages using a stream. | rpc BidiHello(stream HelloRequest) returns (stream HelloResponse); |
| Deadlines/Timeouts | Client specifies maximum wait time for a response before the call fails. | Not applicable |
| Metadata | Key-value pairs sent at the start/end of a call. | Not applicable |
| Error Handling | Communicates errors via status codes and messages. | Not applicable |
| Security | Supports TLS/SSL for secure communication. | Not applicable |
This summary shows the versatility and robustness of gRPC, making it a popular choice for microservices architectures and systems requiring efficient and robust service-to-service communication.
Related reading
- RRSet of type CNAME with DNS name foo.com. is not permitted at apex in zone bar.com
- RRSet with DNS name foo. is not permitted in zone bar
- Running session using tensorflow c api is significantly slower than using python
- RuntimeError module compiled against API version 0xc but this version of numpy is 0xb
- S3 REST API and POST method
- Scale Socket.io vertically AND horizontally - what is the right way to go?
- Securing access to REST API of Kafka Connect
- Securing REST API using custom tokens stateless, no UI, no cookies, no basic authentication, no OAuth, no login page

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.