Why does gRPC operate over HTTP/2 instead of HTTP/1.1? What are the features of HTTP/2?
sobes.tech AI
Answer from AI
gRPC works over HTTP/2, not HTTP/1.1, because HTTP/2 provides a number of key advantages necessary for the efficient operation of gRPC:
-
Multiplexing streams: HTTP/2 allows multiple requests and responses to be sent simultaneously over a single TCP connection without blocking, reducing latency and increasing throughput.
-
Binary protocol: HTTP/2 uses a binary data format, which simplifies parsing and improves performance compared to text-based HTTP/1.1.
-
Header compression: HTTP/2 employs efficient header compression (HPACK), reducing the amount of data transmitted.
-
Request prioritization: HTTP/2 allows setting priorities for streams, which improves resource management.
-
Server push support: HTTP/2 can send data to the client without an explicit request, useful for certain scenarios.
gRPC leverages these capabilities to implement efficient bidirectional streaming, low latency, and high-performance RPC calls.
Unlike HTTP/1.1, where each request blocks the connection until a response is received (head-of-line blocking), HTTP/2 eliminates this problem, which is critical for scalable distributed systems.