Back to all terms
ClientAPIrequestresponseheaders
APIadvanced

gRPC

A high-performance RPC framework using Protocol Buffers for schema definition and HTTP/2 for transport, optimized for service-to-service communication.

Also known as: Google Remote Procedure Call, Protocol Buffers RPC, gRPC-Web

Description

gRPC is a high-performance, language-agnostic RPC framework originally developed at Google that uses Protocol Buffers (protobuf) as its interface definition language and serialization format, and HTTP/2 as its transport protocol. It supports four communication patterns: unary (request-response), server streaming, client streaming, and bidirectional streaming. gRPC is primarily used for internal service-to-service communication in microservice architectures where performance, strong typing, and code generation are priorities.

Protocol Buffers define the service contract in .proto files, specifying services, methods, and message types with field numbers for efficient binary serialization. The protoc compiler generates client stubs and server interfaces in multiple languages (Go, Java, Python, C++, Node.js, etc.), ensuring type safety across service boundaries. Binary serialization is significantly more compact and faster to parse than JSON, reducing network bandwidth and CPU usage -- critical for high-throughput internal APIs.

gRPC's HTTP/2 foundation provides multiplexing (multiple concurrent RPCs on a single connection), header compression (HPACK), and flow control. Streaming support enables efficient patterns like real-time data feeds and progressive uploads. However, gRPC isn't natively supported in browsers (requiring gRPC-Web as a translation layer), and its binary protocol makes debugging harder than JSON-based REST APIs. It's typically deployed behind an API gateway that translates external REST/JSON requests to internal gRPC calls, combining the developer-friendliness of REST for external consumers with the performance of gRPC internally.

Prompt Snippet

Define service contracts in .proto files with explicit field numbers and use buf (buf.build) for linting, breaking change detection, and code generation instead of raw protoc. Generate TypeScript client stubs with ts-proto and Go server interfaces with protoc-gen-go-grpc. Use gRPC interceptors for authentication (validating JWTs from metadata), request logging, and distributed tracing (propagating OpenTelemetry trace context via gRPC metadata). Deploy gRPC services behind Envoy proxy for load balancing with gRPC health checking (grpc.health.v1.Health). Use gRPC-Web via Envoy transcoding for browser clients that need direct access.

Tags

grpcprotobufrpchttp2microservicesperformance