11

I found two possible approaches to deliver notifications after some changes in the Firebase real time database (for example in a chat application):

  • It is possible to use Cloud Functions for Firebase as explained in this blog post.

  • I have also found here another simpler approach using just an android service that listens for changes in the database.

I would like to know what are the pros and the cons of the two approaches before trying to implement one of them and since the second one seems much simpler than the first one.

AL.
  • 36,815
  • 10
  • 142
  • 281
gidan
  • 125
  • 1
  • 1
  • 6
  • 1
    Go for Cloud Functions for Firebase. Less code and less battery use (having an active listener for db changes contributes to battery consumption, which should be avoided) on client side. – AL. May 23 '17 at 23:59

1 Answers1

13

The android service solution described in https://www.codementor.io/sundayakinsete/firebase-real-time-notifications-app-to-app-opkwbo6ba has serious limitations:

  1. it doesn't work when the application is not running (remember that when the user puts your app in background the system could decide to terminate it to free device memory)
  2. it uses extra battery, RAM and network data, to keep the service actively listening for remote database changes
  3. each device with the app running, even in background, would count towards the limit of 100,000 simultaneous connections to the database.
  4. it does not work on iOS

on the other side, if you use Firebase Cloud Messaging (via Cloud Functions or a custom server):

  1. you can receive notifications even if the app is closed
  2. you don't consume extra battery or cpu
  3. you can use the database limit of 100,000 simultaneous connections for the users that are actually using the app in foreground.
  4. it works on iOS and Web
Diego Giorgini
  • 12,489
  • 1
  • 47
  • 50