How does gRPC's use of HTTP/2 multiplexing provide performance advantages over HTTP/1.1-based REST APIs?
Short answer
HTTP/2 allows multiple concurrent requests and responses to be interleaved over a single TCP connection (multiplexing), eliminating HTTP/1.1's head-of-line blocking (where requests on the same connection must complete in order) and avoiding the overhead of establishing multiple…
Advertisement
AModel answer
HTTP/2 allows multiple concurrent requests and responses to be interleaved over a single TCP connection (multiplexing), eliminating HTTP/1.1's head-of-line blocking (where requests on the same connection must complete in order) and avoiding the overhead of establishing multiple TCP connections for concurrent calls -- combined with HTTP/2's header compression (HPACK) and gRPC's compact binary protobuf payloads, this results in meaningfully lower latency and higher throughput for high-volume service-to-service communication compared to typical REST/JSON over HTTP/1.1.
// A single HTTP/2 connection can carry many concurrent gRPC calls
// without head-of-line blocking, unlike sequential HTTP/1.1 requests:
var tasks = new[] {
client.GetOrderAsync(request1),
client.GetOrderAsync(request2),
client.GetOrderAsync(request3)
};
await Task.WhenAll(tasks); // all multiplexed over one connection efficientlyReal-world example
A high-throughput internal service mesh migrates from REST/JSON to gRPC specifically to take advantage of HTTP/2 multiplexing, measurably reducing connection overhead and latency for services making hundreds of concurrent downstream calls per second.
Likely follow-ups
- What is HTTP/1.1 head-of-line blocking specifically, and how does HTTP/2 solve it?
- Does gRPC's binary format meaningfully outperform JSON for typical payload sizes?
Related topics