What is gRPC?

gRPC is an open-source remote procedure call framework. Services define methods and messages in a .proto file, generate typed client and server code, and exchange binary Protocol Buffers messages over HTTP/2.

Also called gRPC API, gRPC protocolUpdated

gRPC is an open-source remote procedure call (RPC) framework. You define a service and its messages in a .proto file, generate client and server code for your languages, and call a method on another service as if it were a local function. Calls travel over HTTP/2, and messages are encoded with Protocol Buffers (protobuf), a compact binary format.

Google built gRPC as the open-source successor to Stubby, the RPC system it had used internally for over a decade, and released it in 2015. As for the full form: the project says the "g" stands for something different in every release. In version 1.0 it stood for "gRPC" itself, making the name recursive, and in 1.1 for "good". It doesn't officially mean "Google".

How it works

You write the contract first:

syntax = "proto3";

service RiskScoring {
  rpc Score (ScoreRequest) returns (ScoreReply);
  rpc WatchAlerts (AlertFilter) returns (stream Alert);
}

message ScoreRequest {
  string application_id = 1;
  int64 amount_paise = 2;
}
message ScoreReply {
  int32 score = 1;
  string decision = 2;
}
message AlertFilter { string portfolio = 1; }
message Alert { string loan_id = 1; string reason = 2; }

The protobuf compiler, protoc, with the gRPC plugin generates a typed server stub in one language and a client in another. The client calls Score with a deadline. gRPC serialises the message, sends it over a long-lived HTTP/2 connection, and returns either a typed reply or a status code such as DEADLINE_EXCEEDED or UNAVAILABLE.

The field numbers (= 1, = 2) identify fields on the wire. You can add new fields without breaking old clients, but never reuse or renumber existing ones.

gRPC has four kinds of method: unary (one request, one response), server streaming, client streaming and bidirectional streaming.

Example: risk scoring in a lending platform

A loan origination system written in Java calls an internal risk model written in Python for every application. Both sides are generated from the .proto file above, so a breaking change to the contract fails the build instead of failing in production. WatchAlerts uses server streaming to push portfolio alerts to a collections service over one connection, instead of that service polling every minute.

gRPC vs REST

gRPC REST (JSON over HTTP)
Contract .proto file, required OpenAPI, optional
Payload Binary protobuf Text JSON
Transport HTTP/2 HTTP/1.1 or HTTP/2
Streaming Built in, both directions Separate: server-sent events or WebSockets
Browsers Needs gRPC-Web or a proxy Native
Debugging Needs tools such as grpcurl curl and a browser
HTTP and CDN caching No Yes

Choose gRPC for internal calls between services, high-volume or low-latency paths, streaming and teams working in several languages. Choose REST for public and partner APIs, where every client and tool already speaks it. An API gateway can expose REST to the outside while services talk gRPC inside.

Things that catch teams out

  • Load balancing. HTTP/2 multiplexes many calls over one long-lived connection, so a connection-level (layer 4) load balancer sends all of a client's calls to one server. Use an HTTP/2-aware balancer, a service mesh or client-side balancing.
  • Missing deadlines. Depending on the language, a client may have no default deadline, so a stuck call can wait a very long time. Set a deadline on every call and pass it down the chain.
  • Errors hidden in replies. Map failures to gRPC status codes consistently, instead of returning OK with an error field inside the message.

Our REST vs GraphQL vs gRPC comparison covers where each style fits.

Any idea in mind? Let's make it real.

Tell us what you're building. You'll hear back from an engineer, not a sales team, usually within one working day.

Book a 30-min call