Video in progress
For calls between internal services, when is it worth moving from REST/JSON to gRPC?
gRPC gives you binary Protobuf, HTTP/2 multiplexing and a strict contract — faster and safer for lots of small internal calls. But it doesn't work with browsers directly and is harder to debug, so the external API usually stays REST.
📖 Answer
REST/JSON's strength is simplicity. You test it with curl, read it in the logs, and every language understands it. For most systems that is enough.
When gRPC pays off:
- there are tens of thousands of calls per second between services and JSON serialization shows up in the profile;
- the contract matters — client and server code are generated from the
.protofile, so you can't get a field type wrong; - you need streaming (server stream, bidirectional);
- teams write in different languages and everyone needs one contract.
service PriceService {
rpc GetPrice (PriceRequest) returns (PriceReply);
}
message PriceRequest { int64 product_id = 1; }
message PriceReply { int64 amount_tiyin = 1; string currency = 2; }
The cost:
- a browser can't call gRPC directly (you need gRPC-Web or a gateway);
- HTTP/2 is a long-lived connection — an L4 load balancer may send all requests to one pod, so you need L7 (Envoy and the like) or client-side balancing;
- extra tools for logs and debugging (grpcurl).
I usually keep the external API as REST, and inside I measure the hot paths and move them to gRPC. A decision like "let's make everything gRPC" taken without measurements usually just adds complexity.
Sign up to mark studied questions and save your progress.