gRPC vs REST — When to Use Each and Why
Two different philosophies#
REST treats APIs as resources you CRUD over HTTP. gRPC treats APIs as functions you call with typed arguments. Both work, but they optimize for different things.
REST in 10 seconds#
GET /api/users/123 → JSON response
POST /api/orders → JSON body → JSON response
Text-based, human-readable, universally supported. Every language, framework, and tool speaks REST.
gRPC in 10 seconds#
service UserService {
rpc GetUser(UserRequest) returns (User);
rpc ListUsers(ListRequest) returns (stream User);
}
Binary protocol (Protocol Buffers), strongly typed, code-generated clients and servers. Built on HTTP/2.
Performance comparison#
| Aspect | REST (JSON) | gRPC (Protobuf) |
|---|---|---|
| Serialization | ~500μs | ~50μs (10x faster) |
| Payload size | 100 bytes | ~60 bytes (40% smaller) |
| Connection | HTTP/1.1 (new per request) | HTTP/2 (multiplexed) |
| Streaming | Workarounds (SSE, WebSocket) | Native bidirectional |
| Latency | Good | Better (binary, multiplexed) |
gRPC is 2-10x faster for most workloads. But performance rarely matters more than developer experience.
When REST wins#
Public APIs. Every developer knows REST. No special tooling needed. curl works. Browser works. Postman works.
Simple CRUD. If your API is creating, reading, updating, and deleting resources, REST's resource model is natural and well-understood.
Browser clients. gRPC doesn't work natively in browsers (requires grpc-web proxy). REST works everywhere.
Caching. REST responses are cacheable by URL. CDNs, browser cache, reverse proxies all work out of the box. gRPC POST requests aren't cacheable.
Small teams. REST has zero learning curve. gRPC requires understanding Protocol Buffers, code generation, and HTTP/2.
When gRPC wins#
Microservice communication. Internal service-to-service calls where you control both ends. The strong typing catches errors at compile time, not runtime.
High-throughput systems. When you're making millions of internal API calls per second, the 10x serialization speedup matters.
Streaming. Server streaming (real-time updates), client streaming (file upload), and bidirectional streaming (chat) are first-class in gRPC.
Polyglot environments. One .proto file generates clients in Go, Java, Python, C++, Node, Rust, and more. Perfect type safety across languages.
Strict contracts. Protocol Buffers enforce a schema. Fields have types, numbers, and explicit rules about backward compatibility.
Protocol Buffers vs JSON#
JSON:
{"id": 123, "name": "Mo", "email": "mo@codelit.io", "active": true}
Human-readable, self-describing, flexible. But no schema enforcement.
Protobuf:
message User {
int32 id = 1;
string name = 2;
string email = 3;
bool active = 4;
}
Binary, smaller, faster. Schema enforced at compile time. But requires code generation and tooling.
Streaming patterns#
gRPC supports four patterns:
Unary: Client sends one request, server sends one response. (Like REST.)
Server streaming: Client sends one request, server streams many responses. (Real-time feeds, large result sets.)
Client streaming: Client streams many requests, server sends one response. (File upload, sensor data.)
Bidirectional: Both stream simultaneously. (Chat, collaborative editing.)
The hybrid approach#
Most modern systems use both:
Browser → REST → API Gateway → gRPC → Microservices
→ gRPC → Database Service
→ gRPC → Auth Service
REST at the edge (public-facing), gRPC internally (service-to-service). Best of both worlds.
Common mistakes#
Using gRPC for browser clients. grpc-web adds complexity. Use REST or GraphQL for browsers.
Using REST for internal high-volume calls. If services make millions of calls to each other, the JSON overhead adds up.
Ignoring backward compatibility. Protobuf has rules: never reuse field numbers, use reserved for removed fields. Break these and you corrupt data.
Visualize your API architecture#
See how REST and gRPC fit together in your system — try Codelit to generate an interactive diagram showing API gateways, microservices, and communication patterns.
Key takeaways#
- REST for public APIs and browsers — universally supported
- gRPC for internal microservices — faster, typed, streaming
- Protobuf is 10x faster than JSON serialization
- HTTP/2 multiplexing eliminates connection overhead
- Hybrid is common — REST at edge, gRPC internally
- Don't optimize prematurely — REST is fine until proven otherwise
Explore the Uber architecture interactively
Try it →Try these templates
OpenAI API Request Pipeline
7-stage pipeline from API call to token generation, handling millions of requests per minute.
8 componentsDistributed Rate Limiter
API rate limiting with sliding window, token bucket, and per-user quotas.
7 componentsAPI Gateway Platform
Kong/AWS API Gateway-like platform with routing, auth, rate limiting, transformation, and developer portal.
8 componentsContinue learning
Go deeper on API design
As an Amazon Associate I earn from qualifying purchases. Codelit may receive a commission at no extra cost to you.
API Design Patterns
JJ Geewax · 2021
Chapter-length treatment of pagination, long-running operations and versioning, with trade-offs.
Contract Testing in Action
Marie Cruz, Lewis Prescott · 2024
Stands up Pact contract tests between consumer and provider and wires them into a CI pipeline.
4.3 (6)Kindle editionBuilding Microservices
Sam Newman · 2021
600 pages on splitting a monolith: service boundaries, data decomposition, migration order.
Software Architecture: The Hard Parts
Neal Ford, Mark Richards, Pramod Sadalage, Zhamak Dehghani · 2021
Works through service granularity, distributed data and saga patterns as full trade-off case studies.
4.6 (731)#2 in Software Design Tools