1

I have a setup like this:

Client <----> Realtime Database <----> AppEngine Server

The AppEngine server has some code inside the servlet init() method.

@Override
public void init(ServletConfig sc) throws ServletException {
  // Setup Firebase....
  firebase.addChildEventListener(..nested SingleValueEventListener..);
}

Whenever the client updates a node in firebase, the AppEngine will listen for this change, and do some processing and update some other nodes.

This setup works for testing, as I am a single user. But what if 100 people are using this app? Am I guaranteed that this childEventListener will run code for every user? Will those nested SingleValueEventListeners also trigger?

Or will I have to deal creating threads on every different firebase request? Or is this all taken care of by Firebase Java Server SDK?

Also, is the init() method, the right place to put the ChildEventListeners and can I add like... 10 listeners in there?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Linxy
  • 2,525
  • 3
  • 22
  • 37

2 Answers2

0

On app engine firebase uses background threads to listen to changes on firebase. By adding ChildEventListener you create a new long living thread in background that will handle everything for you, no need to worry about it and create a new one or etc. It will be triggered by changes in firebase no matter who did those changes(any user of yours can do it). But to use long living background threads on app engine manual scaling is needed to be enabled, that means that only one instance of your back end will run. And it will proceed as many request as it has capabilities, so you have a fixed limit of changes per second that your back end can handle.

Yevgen
  • 4,519
  • 3
  • 24
  • 34
0

I have a similar application going on and we've been working with it for some months. I do not recommend you to use appEngine standard environment for this mean, as it is not prepared to keep persistent connections (we started this way)

Because of this, sometimes we lost connection with firebase and after making some research we found out that this was a common issue. The only way of solving it was migrating the server to the flexible environment

https://cloud.google.com/appengine/docs/flexible/java/migrating-an-existing-app

It is a beta release and I'm not sure about the pricing in the future, but so long it works fine with our application.

Hope this helps you!