🔌 gRPC Advanced

How does gRPC achieve high performance compared to REST?

Answer

gRPC's performance advantage over REST comes from multiple compounding factors: (1) Protobuf binary serialization — encodes integers as variable-length bytes, strings as UTF-8, and omits field names (using numbers instead), producing 3–10x smaller payloads than JSON and deserializing 5–100x faster; (2) HTTP/2 multiplexing — multiple concurrent RPCs share one TCP connection, eliminating the connection establishment overhead that HTTP/1.1 incurs per request (TCP handshake + TLS negotiation ≈ 100ms); (3) HTTP/2 header compression (HPACK) — repeated metadata headers (auth tokens, content-type) are compressed to a few bytes after the first request; (4) Binary framing — HTTP/2 frames are parsed in binary, eliminating the string parsing overhead of HTTP/1.1 text format; (5) Connection reuse — channels maintain persistent connections; (6) Native streaming — streaming RPCs avoid the setup overhead of multiple unary calls for sequential data. Benchmarks typically show gRPC throughput 5–10x higher and latency 2–3x lower than equivalent REST/JSON.