5

While I'm writing a service with grpc, I'm trying to compare http/2 with websocket by server side pushing mechanism.

I know for websocket, the client will send a request with Upgrade: WebSocket and Connection: Upgrade headers to server and establish the long-lived connection. Then server will send the data freely after the connection is established.

But for grpc, as it is routed upon http/2, from the wiki page, https://en.wikipedia.org/wiki/HTTP/2_Server_Push, it says the server would need to predict the potential requests the client would send, and send a PUSH_PROMISE frame as early as possible.

Here are my two questions:

  1. Does it mean that the server would also need to receive a corresponding response(request) from client in response to this PUSH_PROMISE header to decide if client wants to receive or decline the certain push?

  2. In Grpc, if I have a sever side streaming, say send a message every 1 second from server. Does it mean the server need to send a PUSH_PROMISE to client every 1 second or at least before every data frame that server pushes to client?

Shiyu
  • 75
  • 2
  • 5

1 Answers1

8

gRPC does not currently support/use PUSH_PROMISE.

Streaming RPCs in gRPC use HTTP/2 streams; the entire RPC is contained in a request/response in HTTP. The main difference is that HTTP/2 implementations generally allow such streams to be streaming and bidirectional (the client can send more in the request after reading part of the response), while in HTTP/1 that was hit-or-miss.

In gRPC the client will always initiate the RPC. But for server-streaming the server can then reply with multiple messages over time via the stream. This would be similar to the scenario you described with websockets.

Eric Anderson
  • 24,057
  • 5
  • 55
  • 76
  • Thanks! So what is the point of this PUSH_PROMISE here if we can simply push from server to client, I think it just adds more complexity with the term like 'predict' the requests, right? And for now, as I observe, no browser supports grpc, so I'm little bit confused about the explanation in wiki above. – Shiyu Jun 24 '19 at 18:46
  • 1
    Server push is for a different use-case. It allows a server to pre-fill the client's cache which can remove a RTT for small, important resources. – Eric Anderson Jun 24 '19 at 18:53