Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase send notification upon changes in real time database

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.

like image 368
gidan Avatar asked May 23 '17 21:05

gidan


People also ask

Is firebase cloud messaging real time?

This includes downstream messages from servers to client apps, and upstream messages from client apps to servers. Firebase is a cloud service designed to power real-time, collaborative applications.

Can Firebase send push notification?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.

Can I use Realtime Database and firestore at the same time?

You can use both Firebase Realtime Database and Cloud Firestore in your app, and leverage each database solution's benefits to fit your needs. For example, you might want to leverage Realtime Database's support for presence, as outlined in Build Presence in Cloud Firestore.

How does Firebase realtime updates work?

Instead of typical HTTP requests, the Firebase Realtime Database uses data synchronization—every time data changes, any connected device receives that update within milliseconds. Provide collaborative and immersive experiences without thinking about networking code.


1 Answers

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
like image 145
Diego Giorgini Avatar answered Oct 12 '22 15:10

Diego Giorgini