Home > OS >  Does Firestore saves the data to the server immediately using `setDoc` using web JS SDK?
Does Firestore saves the data to the server immediately using `setDoc` using web JS SDK?

Time:12-19

I'm trying to analyze some latency issues, and for than want to understand how setDoc works better. I ran setDoc from one user using the app and it took some time until the other user saw these changes. It would be expected to see close to immediate reflection of changes by the other user.

My understanding is that setDoc will update the local store immediately, and will also sent a request to the Firestore backend immediately. However it may take some time until these changes are applied on the server (e.g. if it requires to update indices), and until they are reflected to other users.

Is this correct?

If this is not correct, and Firestore does not send the updates to the server immediately, when does it send the update? Is there a way to flush them immediately?

CodePudding user response:

Introductory note: "Immediately" is somehow difficult to precisely define in the world of asynchronous operations.

My understanding is that setDoc will update the local store immediately, and will also sent a request to the Firestore backend immediately. However it may take some time until these changes are applied on the server (e.g. if it requires to update indices), and until they are reflected to other users.

If your client device is connected to the internet (i.e. is online), your above statement is correct.

If your client device isn't online the behaviour is different and is explained in the "Access data offline" section of the Firebase documentation.

  • Related