🔌 gRPC Advanced

How does gRPC handle multiplexing in HTTP/2?

Answer

HTTP/2 multiplexing allows multiple logical streams to share a single TCP connection simultaneously. gRPC maps each RPC call to an HTTP/2 stream identified by a unique stream ID. Multiple concurrent RPCs can be in flight over one connection: Stream 1 carries the GetUser request, Stream 3 carries a ListProducts request, Stream 5 carries a CreateOrder request — all active simultaneously without waiting for each other. This solves HTTP/1.1's head-of-line blocking problem (where a slow response blocks subsequent requests on the same connection). In gRPC's streaming RPCs, the entire duration of the stream — which may be minutes — corresponds to one HTTP/2 stream. Flow control operates per-stream: each stream has its own window that prevents fast producers from overwhelming slow consumers. The HTTP/2 connection-level flow control governs total bandwidth. gRPC exposes MaxConcurrentStreams and InitialWindowSize settings to tune these parameters for high-throughput workloads.