0

I have a server that needs to receive real time updates from Firebase, for multiple users, where each user grants Oauth access to his Firebase data to my app.

My server is implemented using Firebase REST Streaming, based on Server Sent Events.

I need to know if there is a way to multiplex Firebase data pertaining to multiple users on a single stream.

I would like to be able to set up the stream with Oauth tokens pertaining to multiple users, and to subsequently receive real time updates pertaining to the multiple users on the same stream.

Otherwise, it seems that I need to maintain a separate stream per Oauth token, which seems to be non-scalable.

I think Twitter have a Site Streams feature like what I am looking for in their API, implemented via an envelope that indicates the user the message is targetted to.

Does Firebase support anything similar?

Yoni Rabinovitch
  • 5,171
  • 1
  • 23
  • 34

1 Answers1

2

A single Firebase REST call will only monitor a single node. E.g.

curl 'https://samplechat.firebaseio-demo.com/users/jack/name.json'

You can control what data is returned from under that node with the orderBy, startAt,endAtandlimitTo...` parameters. E.g.

curl 'https://samplechat.firebaseio-demo.com/users/.json?orderBy="name"&startAt="Jack"'

There is no way to have a single REST request return data from different nodes/nodesets. So unless you find a way to gather all data you want to return under single node, where it can be returned by a single set of query parameters (orderBy, etc), you will have to execute multiple REST requests to get your data.

Note that the SDKs that Firebase provides internally use a web-socket protocol, so are not impacted by this limitation. If an SDK is available for your server-side language (e.g. node.js, Java), you could solve it by using that one.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    Thanks. I started off by using the node.js SDK in my server. However, there I was hit by the limitation described in [link](http://stackoverflow.com/questions/28242306/how-to-use-firebase-client-to-connect-to-nest-api-using-multiple-client-connecti).The solution described there (to use an undocumented second parameter to the Firebase constructor, that instructs the instance to set up and maintain a new TCP connection rather than sharing the common one) works, HOWEVER what I am looking for is to share the TCP connection, rather than have to create a new one for each user. Can that be done? – Yoni Rabinovitch May 27 '15 at 13:32
  • 2
    *[Disclaimer: I work for Firebase]* The Firebase server currently requires a separate connection for each context/token. There is nothing you can do client-side to change that. There may be a library to multi-plex connections, but *something* will in the end have to keep a socket open for every context. If it doesn't scale well enough for your client-side needs, you'll have to look at another approach. – Frank van Puffelen May 27 '15 at 14:15
  • 2
    So that seems to imply that, for example, the Works With Nest API, that is based on Firebase, is inherently non-scalable. I mean, if my app serves 1 million Oauth'd Nest subscribers, then my server needs to keep 1 million connections open with Firebase. Am I missing something? If that's the case, then I don't understand why Nest based their API on Firebase. Do Firebase have any plans to address this issue, and to provide some kind of multiplexed connections? I would assume any server-side app integrating with Firebase hits this limitation. – Yoni Rabinovitch May 27 '15 at 19:16