RPC (Remote Procedure Call) is a concept that allows a program to execute a procedure (function) on another machine as if it were a local function call.
Examples of RPC frameworks:
- JSON-RPC
- XML-RPC
- gRPC --
gRPC is an open-source, high-performance RPC framework developed by Google It is designed for efficient communication between services in distributed systems such as microservices.
- Language-agnostic (supports many programming languages)
- High performance (built on top of HTTP/2)
- Supports streaming (client, server, and bidirectional)
- Uses Protocol Buffers (Protobuf) for efficient serialization
- Auto-generates code from
.protofiles - Secure communication (supports TLS/SSL)
- Define your service and messages in a
.protofile. - The
.protofile acts as a contract between services. - Use the
protoccompiler to generate client and server code in your target language. - Implement the server logic and run the gRPC server.
- The client calls methods as if they were local functions.
syntax = "proto3";
service UserService {
rpc GetUser (GetUserRequest) returns (GetUserResponse);
}
message GetUserRequest {
string id = 1;
}
message GetUserResponse {
string id = 1;
string name = 2;
string email = 3;
}gRPC supports four communication types:
-
Unary RPC
- Client sends a single request → Server returns a single response.
-
Server Streaming RPC
- Client sends a single request → Server sends multiple responses (stream).
-
Client Streaming RPC
- Client sends multiple requests (stream) → Server sends a single response.
-
Bidirectional Streaming RPC
- Both client and server send a stream of messages to each other.
| Feature | gRPC | REST |
|---|---|---|
| Protocol | HTTP/2 | HTTP/1.1 |
| Data format | Protobuf (binary, compact) | JSON (text, verbose) |
| Performance | Faster (binary, multiplexing) | Slower (text, no multiplexing) |
| Streaming | Supported (bi-directional) | Limited (SSE, WebSocket) |
| Code generation | Automatic from .proto |
Manual, boilerplate |
| Browser support | Limited (needs gRPC-Web) | Native support |
Use gRPC when:
- You have microservices that need to communicate efficiently.
- Low latency and high throughput are critical.
- You need bi-directional streaming (e.g., chat apps, IoT, real-time updates).
- You want strict contracts between services with auto-generated code.
Use REST when:
- You need direct browser-to-server communication.
- Simplicity and human-readable APIs are more important than performance.
- You are building public APIs widely consumed by different clients.
- High performance and efficiency (binary Protobuf + HTTP/2).
- Strongly typed contracts between services.
- Supports streaming and multiplexing.
- Auto code generation reduces boilerplate.
- Not natively supported by browsers (requires gRPC-Web).
- Harder to debug compared to JSON APIs.
- Learning curve for Protobuf and gRPC tooling.
- RPC is a concept.
- gRPC is a modern, fast, language-agnostic framework for RPC, created by Google.
- It’s widely used in microservices architectures because of its speed, reliability, and streaming capabilities.
- REST is still preferred for browser-facing APIs, but gRPC is the better choice for service-to-service communication in distributed systems.