5

Some StackOverflow posts and this informative blog post (but possibly outdated) suggest that HTTP/2 as currently implemented in browsers doesn't yet support push streaming, and that WebSockets or SSE should still be used when this functionality is needed.

I'm curious how Google Firestore, which implements gRPC over HTTP achieves this. From what I can tell after opening a site that uses Firestore, none of the following are used:

  • WebSockets - DevTools doesn't show any open Websockets. Also this.
  • SSE - I couldn't find "eventsource" anywhere in DevTools sources or in relevant source code
  • WebRTC - Not applicable. I also couldn't find anything in chrome://webrtc-internals
  • HTTP/2Server Push (aka Push_Promise) - Irrelevant

Questions

  1. Is FireStore simply using something similar to long polling, where the client opens an HTTP/2 stream (or HTTP/3 when using Chrome) with the server, and that server just keeps that stream open to pushes messages whenever it needs to.
  2. Is this made possible by some recent advancements in HTTP/2 browser implementations or have server/client software library developers simply figured out a way to emulate server-> client push streaming using this long polling method.
  3. If the above is true, can we now (in 2021) say that HTTP/2 can on its own achieve the same functionality provided by WebSockets and/or SSE, and that WebSockets are on their way to obsolescence.
el_tigro
  • 1,099
  • 2
  • 10
  • 22

1 Answers1

4

It appears that Firestore is not using gRPC in the browser at all. Instead, when running in the browser, they use a WebChannel. This is an abstraction that enables traditional HTTP requests as well as streaming. It seems that a WebChannel will use polling when the browser does not support streaming natively.

I don't know the backstory of why Firestore went in this direction, but it isn't a fundamental limitation of gRPC in the browser or of HTTP/2 in the browser. The main feature of HTTP/2 left out by (most) browser implementers is trailers. The grpc-web project is an implementation of a subset of the gRPC protocol meant to run in the browser and work around the lack of trailer support. This subset includes server-side streaming and should be well suited to the Firestore use case.

Richard Belleville
  • 1,445
  • 5
  • 7