gRPC (Google Remote Procedure Call)
Definition:
gRPC is a high-performance, open-source framework developed by Google that lets services communicate with each other using Remote Procedure Calls (RPC) — just like calling a local function, but across a network.
Core Idea:
“Call a method on a remote server as if it were a local function.”
Key features
| Feature | Description |
|---|---|
| Protocol | Uses HTTP/2 (faster, multiplexed, binary) |
| Serialization | Uses Protocol Buffers (protobuf) — compact & fast |
| Bi-directional Streaming | Supports client → server, server → client, and 2-way streaming |
| Strong Typing | Strict types defined in .proto files |
| Code Generation | Auto-generates client/server code in multiple languages from .proto |
| Efficient | Much faster than JSON/REST over HTTP/1.1 |
How It Works:
- Define service & messages in a .proto file
- Compile it → generates client & server code
- Services call each other using typed methods over HTTP/2
gRPC vs REST API:
| Feature | gRPC | REST |
|---|---|---|
| Protocol | HTTP/2 | HTTP/1.1 (mostly) |
| Data Format | Protobuf (binary, compact) | JSON (text, verbose) |
| Speed | Faster | Slower |
| Streaming | Built-in bi-directional | Limited |
| Browser Support | Poor (requires extra tools) | Native |
| Human-readable | No | Yes |
When to Use gRPC:
✅ Microservices communication ✅ Low-latency, high-throughput systems ✅ Internal services (where browser support isn’t needed) ❌ Avoid for public APIs (due to poor browser support)
Used by:
- Netflix
- Dropbox
- Square