Skip to content

gRPC โ€” Remote Procedure Call Framework

Last reviewed: 2026-05-29

gRPC is a high-performance, open-source universal RPC framework initially developed by Google. It uses HTTP/2 for transport, Protocol Buffers (protobuf) for serialization, and enables client-server communication across languages and platforms.


Overview

gRPC is designed for low-latency, high-throughput communication, especially between microservices. It supports four communication patterns:

Pattern Description
Unary RPC Client sends one request, server returns one response (like HTTP/REST)
Server Streaming Client sends one request, server streams multiple responses
Client Streaming Client streams multiple requests, server returns one response
Bidirectional Streaming Both sides send/receive streams concurrently

Training Content

  • Protocol Buffers definition (.proto files)
  • Code generation with protoc
  • Unary and streaming RPC patterns
  • gRPC in Go (server + client implementation)
  • gRPC in Python
  • Interceptors/middleware
  • Error handling and deadline propagation
  • TLS/mTLS for secure gRPC connections
  • gRPC Gateway (REST โ†” gRPC transcoding)

Protocol Buffers Definition

syntax = "proto3";

package order;

service OrderService {
  rpc CreateOrder (CreateOrderRequest) returns (Order);
  rpc GetOrder (GetOrderRequest) returns (Order);
  rpc ListOrders (ListOrdersRequest) returns (stream Order);  // Server streaming
}

message CreateOrderRequest {
  string user_id = 1;
  repeated string item_ids = 2;
}

message Order {
  string id = 1;
  string user_id = 2;
  repeated string item_ids = 3;
  double total = 4;
  int64 created_at = 5;
}

gRPC vs REST

Feature gRPC REST
Transport HTTP/2 HTTP/1.1, HTTP/2
Serialization Protocol Buffers (binary) JSON, XML (text)
Contract Required .proto schema Optional (OpenAPI)
Streaming Native bidirectional SSE, WebSocket add-ons
Performance ~5โ€“10ร— faster than JSON Slower due to text parsing
Browser support Requires gRPC-Web Native
Code generation Built-in (protoc) Manual or OpenAPI generators
Human readability Low (binary wire format) High (readable JSON)

Key Concepts

HTTP/2 Benefits

  • Multiplexing โ€” Multiple requests over a single TCP connection
  • Header compression (HPACK) โ€” Reduces overhead
  • Server push โ€” Server sends resources before requested
  • Flow control โ€” Per-stream control

Proto3 Features

  • Strong typing โ€” Compile-time type checking
  • Backward compatibility โ€” Field numbers allow evolution
  • Cross-language โ€” Code generation for Go, Python, Java, C++, etc.
  • Small payloads โ€” Binary encoding โ‰ˆ 10ร— smaller than JSON
  • Fast serialization โ€” Up to 100ร— faster than JSON parsing

gRPC Ecosystem

Component Description
protoc Protocol Buffers compiler
protoc-gen-go / protoc-gen-go-grpc Go code generation plugins
grpc-gateway REST โ†” gRPC transcoding proxy
gRPC-Web Browser client support
Envoy proxy gRPC load balancing (L7)
gRPC health probe gRPC health checking protocol

Authentication

// TLS connection (recommended)
creds, _ := credentials.NewClientTLSFromFile(certFile, "")
conn, _ := grpc.Dial(address, grpc.WithTransportCredentials(creds))

// With JWT token (interceptor metadata)
// Client adds token to context:
ctx := metadata.AppendToOutgoingContext(ctx, "authorization", "Bearer <token>")

// Server validates via interceptor

Resources