2

I have a question about a theoretical situation and how the Firestore JS SDK handles it.

The setup is:

  • We have offline persistence enabled.
  • We're offline
  • We need to get() from collection A immediately after coming online.

I'm gonna exaggerate the numbers to make the situation more easily graspable.

Steps

  1. While offline, we add 1000000 documents to collection A.
  2. We come back online, and the assumption is that Firestore starts synching the local data from Collection A to the server, which will take a while.
  3. We do a get() from collection A, while Firestore might not yet have finished synching.

What happens? The assumption here is that, seeing as Firestore has detected we're online again, it tries to get the documents from Collection A that are found in the online DB, and thus might miss out on some of the documents that is still being synchronized from step 2.

Can a Firebase engineer clarify what would happen in this scenario?

DarkNeuron
  • 7,981
  • 2
  • 43
  • 48

1 Answers1

2

A local client will always see its own changes. So even while you're offline, it will see the changes you've made locally in the collection. When you're back online, it will see the changes it's made locally too, regardless of whether those have been synchronized to the server yet.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Perfect, good to know. That alleviates our concern about `get()` getting incomplete data. – DarkNeuron Nov 28 '17 at 14:51
  • I'd be interested to learn how it copes with additions from other clients. If you get a chance to look at https://stackoverflow.com/questions/47111181/firestore-offline-data-merging-writes-maximum-time-of-offline-persistence, that would be great. – Duncan Jones Oct 16 '18 at 17:06
  • Ahah, found this answer from you https://stackoverflow.com/questions/51083190/firestore-what-happens-when-an-offline-device-goes-online – Duncan Jones Oct 16 '18 at 17:07