4

I was wondering, how does Firestore handle real-time syncing of deeply nested objects? Specifically, does it only sync the diff?

For example, I have a state of the app which is just an array of 3 values and this state is synced between devices. If I then change one of the values will the whole new array be synced (transmitted on the network) or only the diff? What if my state is the nested object?

I'm asking because I want to sync the whole state which is an object with multiple fields but I don't wont to sync the whole object when I only change single field.

iezepov
  • 455
  • 3
  • 12
  • did my answer help you? –  May 08 '18 at 20:48
  • @Eminem That's a nice answer, but I'm not sure that we can trust vague statements in documentation in this one. I tried to actually test it (sync a large object and then update some field in it) and it looked like it was always syncing the whole state. But maybe what I did is totally wrong. – iezepov May 11 '18 at 06:34
  • vague statements? It's all taken from firebase documentation, it's a logical conclusion –  May 11 '18 at 06:41

1 Answers1

-2

Like Realtime Database, Cloud Firestore uses data synchronization to update data on any connected device. However, it's also designed to make simple, one-time fetch queries efficiently.

Queries are indexed by default: Query performance is proportional to the size of your result set, not your data set.

Cloud Firestore will only send your device only the difference of the document.

Tips: Add queries to limit the data that your listen operations return and use listeners that only download updates to data.

Place your listeners as far down the path as you can to limit the amount of data they sync. Your listeners should be close to the data you want them to get. Don't listen at the database root, as that results in downloads of your entire database. Hope it helps!

  • 1
    Can you give a source for the "Cloud Firestore will only send your device only the difference of the document"? – Frank van Puffelen Apr 29 '18 at 22:10
  • Frank that's my conclusion from the firestore documentation –  Apr 30 '18 at 05:51
  • @FrankvanPuffelen is my conclusion right?since you work on Firestore your thoughts are welcome! –  May 09 '18 at 08:49
  • 2
    @FrankvanPuffelen Hi, Frank, It would be really nice to hear from you or anyone from Firebase itself something regarding this question. – iezepov May 12 '18 at 08:20
  • 1
    I don't believe you only get updates when listening for changes, you get document/s. If listening to a document reference you will get a single document(DocumentSnapshot). If you have a query listening to changes in a collection reference, you will get back the documents returned by your query (QuerySnapshot, which contains QueryDocumentSnapshots) https://firebase.google.com/docs/firestore/query-data/listen @FrankvanPuffelen It this correct? – SammyT Sep 09 '18 at 12:35
  • 3
    This answer is incorrect. Firebase does not synchronize the difference in a document but instead sends the entire document on every change. – Ray Li Oct 20 '19 at 22:46