Video in progress

Strong Middle 🧩 Microservices

When do you choose gRPC instead of REST for calls between internal services, and what are its traps?

gRPC is handy when there are many internal calls, a strict contract, streaming or low latency is needed: Protobuf is compact, code is generated, and HTTP/2 carries many requests over one connection. The traps: load balancing, difficulty debugging, and not working directly with browsers.

📖 Answer

These are gRPC's strengths in practice:

  • The .proto file is the single contract. Client and server code is generated from it, so you can't make a mistake in a field name.
  • Protobuf is much more compact than JSON and parses faster; at tens of thousands of internal calls per second you notice it in CPU.
  • Deadlines, cancellation and streaming are in the protocol itself.
service InventoryService {
  rpc Reserve (ReserveRequest) returns (ReserveReply);
}

message ReserveRequest {
  string order_id = 1;
  repeated Item items = 2;
}

The compatibility rule in Protobuf is simple: never change or reuse a field number. Mark the number of a removed field as reserved.

The traps:

Load balancing. gRPC uses one long-lived HTTP/2 connection. A Kubernetes ClusterIP Service pins the connection to one pod once, and all later requests go to that pod while newly added pods sit idle. The fix: a headless Service and round_robin on the client side, or a service mesh (L7 balancing).

Debugging. You can't check it with curl; you need grpcurl or server reflection. The logs contain binary payloads.

Error model. gRPC statuses (UNAVAILABLE, DEADLINE_EXCEEDED) instead of HTTP status codes. You have to rewrite your retry rules based on them.

For external and browser-facing APIs I stay with REST/JSON. I choose gRPC for internal, high-traffic calls with a stable contract, and only if the team is ready to operate it.