26

https://firebase.google.com/docs/firestore/manage-data/enable-offline

How does Firestore work with offline data?

  1. How are writes merged by many clients editing the same data offline, that then come online at the same time?

  2. How long is offline data persisted? If my user uses my app for 5 years offline, then comes back online, will this be an issue? Do offline changes persist after device restarts?

  3. Does query performance of offline data degrade as the data set gets larger?

Im specifically interested in the web Firestore client.

Do all the language clients implement the above in the same manner?

Thanks.

zino
  • 1,222
  • 2
  • 17
  • 47
  • 3
    I am quite interested in it as well. There is practically no information on it in official docs, which makes offline capabilities a very risky thing to use. – artur grzesiak Nov 10 '17 at 11:31
  • I hope we get an answer from awesome Firesstore engineer. Fully agree on your points. In my tests I was not able to rely on Firestore offline capabilities for `Documents` and `Collections`, Also it seems that local updates are not considered as a legitimate document update and we need to check for `hasLocalChanges` to restart the update process ? – mosn Nov 10 '17 at 17:11
  • Having placed the bounty, I then found https://stackoverflow.com/questions/51083190/firestore-what-happens-when-an-offline-device-goes-online. Which covers much of the same ground. – Duncan Jones Oct 16 '18 at 17:07
  • @DuncanJones Please see my below answer. – Alex Mamo Oct 21 '18 at 05:00

1 Answers1

22

How are writes merged by many clients editing the same data offline, that then come online at the same time?

The write operations that will take place on Firebase servers, will be in the order in which that series of operations happened. The last operation (the most recent one) will be the one that will be available in the database by the time the synchronization occurs.

How long is offline data persisted? If my user uses my app for 5 years offline, then comes back online, will this be an issue?

The problem is not about how long is about how many operations do you make while the device is offline. While offline, Firestore will keep in queue all the write operations. As this queue grows, local operations and app startup will slow down. Nothing major, but over time these may add up. The major problem in this case is that the end result of this will be that the data on the server stays unmodified. Then what is the purpose of a realtime database? Firestore is really designed as an online database that came work for short to intermediate periods of being disconnected, not to stay offline for 5 years. Beside that, in 5 years it might be a problem of compatibility and not of the number of writes.

Do offline changes persist after device restarts?

The offline persistence is also called disk persistence. This type of persistence is enabled by default in Cloud Firestore and it means that recently listened data (as well as any pending writes from the app to the database) are persisted to disk. The data in this cache survives app restarts and device reboots.

Does query performance of offline data degrade as the data set gets larger?

Yes it does, like explained above.

Do all the language clients implement the above in the same manner?

No. For iOS and Android, the offline feature works fine while for web, this feature is still experimental.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • 1
    Does it understand single fields being update while offline? For example, if we have document with `name: string` and `counter: number`. Let's say we have 2 offline clients. One increments the counter, and the other updates the name. When they both sync their changes, will the document reflect both changes, or will it only reflect that last write operation? – DarkNeuron Sep 26 '19 at 09:54
  • 2
    Ok, so I just tested this myself, using two offline clients, and the result was what I was hoping for above. Both clients ONLY affected the field they updated! – DarkNeuron Sep 26 '19 at 10:39
  • @DarkNeuron Yes, will reflect both changes. – Alex Mamo Sep 29 '19 at 10:38