# Real time app sync in Ionic

**URL:** <https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141>\
**Category:** Ionic Framework\
**Created:** [September 17, 2021, 5:43pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141 "2021-09-17T17:43:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![usanzadunje](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/usanzadunje/32/136754_2.png) [@usanzadunje](https://forum.ionicframework.com/u/usanzadunje)\
**Post date:** [September 17, 2021, 5:43pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/1 "2021-09-17T17:43:09Z")

</div>

Hello guys,

I want to achieve following functionality : I have data that is displayed to users, one user can change the data and I want all other user to see the changed immediately. I want real time communication between users. I thought, since I use Firebase Cloud Messaging, to send notification to all users and on “pushNotificationReceived” event I update their data.

My question is: Is this good solution to the problem, what would be the better way?

Also since I send Push Notification using Firebase, it is displayed to user, is there a way to send it without showing Push Notification to user just so event triggers and I update information.

---

<div class="post-metadata">

**Author:** ![EinfachHans](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/einfachhans/32/130917_2.png) [@EinfachHans](https://forum.ionicframework.com/u/EinfachHans)\
**Post date:** [September 17, 2021, 5:48pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/2 "2021-09-17T17:48:58Z")

</div>

I mostly use Push notifications for szencarios like that yes. And you should search for **FCM Data Push Notifications** 😏

---

<div class="post-metadata">

**Author:** ![usanzadunje](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/usanzadunje/32/136754_2.png) [@usanzadunje](https://forum.ionicframework.com/u/usanzadunje)\
**Post date:** [September 17, 2021, 5:51pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/3 "2021-09-17T17:51:33Z")

</div>

Thanks for advice. I will look into that!

---

<div class="post-metadata">

**Author:** ![usanzadunje](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/usanzadunje/32/136754_2.png) [@usanzadunje](https://forum.ionicframework.com/u/usanzadunje)\
**Post date:** [September 25, 2021, 2:16pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/4 "2021-09-25T14:16:03Z")

</div>

@EinfachHans Hey, I have one more question for you. When I register token from client app it is stored on backend. Is it possible that Firebase invalidates token or do they have expiry date. If yes how can I know when this happens so I can notify my backend to change token for new one?

---

<div class="post-metadata">

**Author:** ![Tommertom](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tommertom](https://forum.ionicframework.com/u/Tommertom)\
**Post date:** [September 25, 2021, 5:17pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/5 "2021-09-25T17:17:43Z")

</div>

I am sure you are way better off using realtime listners on firestore instead fcm if u want under the hood realtime updates without notifications

---

<div class="post-metadata">

**Author:** ![usanzadunje](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/usanzadunje/32/136754_2.png) [@usanzadunje](https://forum.ionicframework.com/u/usanzadunje)\
**Post date:** [September 25, 2021, 5:46pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/6 "2021-09-25T17:46:33Z")

</div>

@Tommertom  
I am using Firebase only for FCM. I have my Laravel backend.

One user adds a number to total store i need to notify all other users in same group about it and add +1 to their store as well. In this scenario would you suggest i keep with Firebase notification for real time updates or something else. What would you suggest?

---

<div class="post-metadata">

**Author:** ![Tommertom](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tommertom](https://forum.ionicframework.com/u/Tommertom)\
**Post date:** [September 25, 2021, 5:51pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/7 "2021-09-25T17:51:55Z")

</div>

No recommendation

If u have to stick to laravel then i cant tell the best way how to trigger updates for a larger group. I dont know laravel backends. Likely there is a laravel solution to this?

Using fcm without user notifications- maybe a bit off? But if hans says it works, why not. Not sure if u can disable the notification while still getting the push. Maybe in message config?

In firestore the realtime updating is a default feature and pretty cool. If u like that, maybe ditch laravel? Or even put firestore in between? Or next to the laravel api?

---

<div class="post-metadata">

**Author:** ![EinfachHans](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/einfachhans/32/130917_2.png) [@EinfachHans](https://forum.ionicframework.com/u/EinfachHans)\
**Post date:** [September 25, 2021, 6:19pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/8 "2021-09-25T18:19:58Z")

</div>

We are using Push but that doesn’t mean that it’s the best 😃 Can you share some information about firestore realtime updates also in cordova/capacitor apps? Always happy to learn new stuff 😊

---

<div class="post-metadata">

**Author:** ![Tommertom](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tommertom](https://forum.ionicframework.com/u/Tommertom)\
**Post date:** [September 25, 2021, 6:32pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/9 "2021-09-25T18:32:18Z")

</div>

> [@EinfachHans](#):
>
> Can you share some information about firestore realtime updates also in cordova/capacitor apps?

Uhhh…. I use firebase web sdk to access data in firestore. Via angularfire wrapper

A doc(‘pathtodoc’).valueChnges() gives a stream of that doc. Whenever another app or server changes that doc, all who are subscribed to the stream will get those changes almost realtime. All with rxjs magic

U not using firestore then I presume?

> <https://github.com/angular/angularfire/blob/dd414b243c2e3987de5e25d33def647bbb8047fd/docs/firestore/documents.md>

---

<div class="post-metadata">

**Author:** ![EinfachHans](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/einfachhans/32/130917_2.png) [@EinfachHans](https://forum.ionicframework.com/u/EinfachHans)\
**Post date:** [September 25, 2021, 6:39pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/10 "2021-09-25T18:39:37Z")

</div>

No not yet. Our App is highly important to run and receive updates even after hours in background mode. It’s a emergency app, so stuff like this has to work perfectly over hours 😃 Even with internet connection losses and resuming…

---

<div class="post-metadata">

**Author:** ![Tommertom](https://avatars.discourse-cdn.com/v4/letter/t/ed8c4c/32.png) [@Tommertom](https://forum.ionicframework.com/u/Tommertom)\
**Post date:** [September 25, 2021, 6:49pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/11 "2021-09-25T18:49:42Z")

</div>

Ok sounds cool

Firestore allows for flaky connections and offline mode, and is pretty efficient in resources.

[![](https://global.discourse-cdn.com/ionicframework/original/3X/c/d/cd82847e7ca614d10e847478de2654cd4a914344.jpeg "To Realtime or Not? | Get to know Cloud Firestore #10") ](https://www.youtube.com/watch?v=3aoxOtMM2rc)

[![](https://global.discourse-cdn.com/ionicframework/original/3X/b/4/b494609464ea5aeea3ed63de82a7871a67e971e0.jpeg "How do I Enable Offline Support? | Get to know Cloud Firestore #9") ](https://www.youtube.com/watch?v=oDvdAFP6OhQ)

But of course cant say for mission critical stuff.

Can u share your techstack?

---

<div class="post-metadata">

**Author:** ![EinfachHans](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/einfachhans/32/130917_2.png) [@EinfachHans](https://forum.ionicframework.com/u/EinfachHans)\
**Post date:** [September 25, 2021, 7:01pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/12 "2021-09-25T19:01:11Z")

</div>

We are using latest Cordova Version (because we need native Google Maps integration) with Ionic.

Sounds interessting, i will check it out 😊 Thanks!

---

<div class="post-metadata">

**Author:** ![usanzadunje](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/usanzadunje/32/136754_2.png) [@usanzadunje](https://forum.ionicframework.com/u/usanzadunje)\
**Post date:** [September 25, 2021, 7:43pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/13 "2021-09-25T19:43:14Z")

</div>

Actually when you send data notification there is nothing displayed. It is silent and i can do whatever i want with data. There isnt even push when app is in background.

Also reimplementing everything to use firestore seems ineficent since my app and real time part doesnt need to be exact in milisecond or even few seconds.

But thanks for info will defenitely look i to ir for future projects.

---

<div class="post-metadata">

**Author:** ![usanzadunje](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/usanzadunje/32/136754_2.png) [@usanzadunje](https://forum.ionicframework.com/u/usanzadunje)\
**Post date:** [September 25, 2021, 7:46pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/14 "2021-09-25T19:46:55Z")

</div>

Do you by any chance use distance calculation in your app? If so which plugin you use?

I have distance calculation using some formula using lat and lng but its not calculating distance using roads like an google mapa does. It just calculates air distance which is not always 100% exact.

---

<div class="post-metadata">

**Author:** ![EinfachHans](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/einfachhans/32/130917_2.png) [@EinfachHans](https://forum.ionicframework.com/u/EinfachHans)\
**Post date:** [September 25, 2021, 9:10pm UTC](https://forum.ionicframework.com/t/real-time-app-sync-in-ionic/215141/15 "2021-09-25T21:10:06Z")

</div>

nope but i guess google has a library for that?
