Skip to content
gRPC
step 1/5

Reading — step 1 of 5

Read

~1 min readProduction

gRPC

gRPC is an RPC framework on top of protobuf + HTTP/2.

Service definition:

syntax = "proto3";

service UserService {
    rpc GetUser (GetUserRequest) returns (User);
    rpc CreateUser (CreateUserRequest) returns (User);
    rpc ListUsers (ListUsersRequest) returns (stream User);
    rpc UpdateUsers (stream UpdateUsersRequest) returns (UpdateUsersResponse);
    rpc Chat (stream ChatMessage) returns (stream ChatMessage);
}

4 RPC types:

  1. Unary: 1 req → 1 resp.
  2. Server streaming: 1 req → N resp.
  3. Client streaming: N req → 1 resp.
  4. Bidirectional streaming: N req ↔ N resp.

Generated code: stubs (client + server).

python

HTTP/2:

  • Multiplexed: many RPCs over one connection.
  • Bidi streams.
  • Header compression (HPACK).
  • Long-lived connections.

vs REST:

  • Faster (binary, multiplex).
  • Strict schema.
  • Streaming native.
  • Browser support poor (need gRPC-Web).
  • Cross-org adoption: REST often easier.

Auth:

  • TLS standard.
  • Per-call metadata for auth tokens.
  • mTLS for service-to-service.

Errors:

  • Status codes: OK, INVALID_ARGUMENT, NOT_FOUND, INTERNAL, etc.
  • Status details (proto): structured error info.

Deadlines:

  • Per-RPC timeout.
  • Propagated through call chain.
  • Cancellation cascades.

Production gRPC:

  • Used heavily in microservices (Google, Uber, Square).
  • Service mesh integration (Envoy proxy).
  • Observability: OpenTelemetry hooks.

Alternatives:

  • REST + JSON: ubiquitous.
  • Connect: gRPC + REST interop.
  • GraphQL: query language; different abstraction.
  • Twirp: simpler RPC over HTTP/1.1 + protobuf.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…