Hi have to use firestore in offline online synario for chat application. For example some time user send message to other user but there is no internet connection. But just when user switched on internet connection message should instantly sync into data based. Its working in firebase but don't know how it work in firestore.
1 Answers
Yes, it work also with Firestore. As the offical documentation says,
Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data. When the device comes back online, Cloud Firestore synchronizes any local changes made by your app to the data stored remotely in Cloud Firestore.
To be more clear, every client that is using a Firestore database and sets PersistenceEnabled
to true
, maintains it's own internal (local) version of the database. When data is inserted/updated, it is first written to this local version of the database. As a result, all writes to the database will trigger local events immediately, before any data has even been written to the server. This means that the app will remain responsive regardless of Internet connectivity.
So, feel free to use Firestore offline capabilities.

- 130,605
- 17
- 163
- 193
-
4Alex thanks for the reply but Goolge document tells on for get and query data offline not how to insert it because at offline condition OnFailureListener get instantly called. – saurabh dixit Nov 02 '17 at 10:39
-
@saurabhdixit: if you're having problems with this functionality, I recommend updating your question with the [minimal code that reproduces the problem](http://stackoverflow.com/help/mcve). It is much easier to help if we see what you've done. – Frank van Puffelen Nov 02 '17 at 14:58
-
Thank you! @FrankvanPuffelen – Alex Mamo Nov 02 '17 at 15:32
-
on syching its not clear to me, does the data that we write to firestore sync to firestore once the device has internet ? is there an automatic mechanism to do this ? – Axil Sep 21 '19 at 03:34
-
@Axil Yes, once you get back online everything will be pushed to the Firebase servers. And yes, there is an automatic mechanism for that. – Alex Mamo Sep 21 '19 at 08:32
-
@AlexMamo - "when the device is back online". Does this mean that the user doesn't have to start the app? Or does the device needs ot be back online and the user needs to start the app for data to sync? – Daniel Dimitrov Jun 08 '20 at 07:43
-
@DanielDimitrov I'm not sure I understand your questions. I recommend you post a new question using its own [MCVE](https://stackoverflow.com/help/mcve), so I and other Firebase developers can help you. – Alex Mamo Jun 09 '20 at 07:34
-
The question is related to the same topic. What does it exactly mean "when the device is back online". User is offline - he uses appA. He closes appA. Few minutes later the device of the user is online, but appA is not started. Is firestore somehow able to "magically" sync data in the background without starting the app? Or do we have to start the app for data to sync? – Daniel Dimitrov Jun 09 '20 at 08:03
-
@DanielDimitrov Check **[this](https://stackoverflow.com/questions/48699032/how-to-set-addsnapshotlistener-and-remove-in-populateviewholder-in-recyclerview/)** out. – Alex Mamo Jun 09 '20 at 08:09
-
2I am having trouble inserting/updating data offline, when device is offline the callbacks OR completion blocks are not called and the data is bieng updated locally but i dnt get the completion callbacks – Shahzaib Qureshi Jun 09 '20 at 09:45