Data synchronization between databse and web app - google-cloud-firestore

Do you know better solution for 'data streaming' instead of firestore?
I mean situation like this (every change in firestore is streamed to the web app)
web app <-synced wiht-> firestore
I need more efficient solution (more than 1k writes per second)

Related

Considerations for data syncing methods - flutter project/ task management app

I have been teaching myself flutter over the past few months, and am hoping to build simple project/task management app that will stay in synch across devices. I had a more foundational question about the considerations for best methods to get/update/synch data.
Method 1:
Get data from Firestore
Store data in local list of custom task objects
Perform any updates/queries on local list
At some point, re-synch updates to local list back to Firestore (I'm unsure of the optimal way to do this (e.g., before closing app, at a regular frequency?)
Method 2:
Generate a Stream from Firestore
Perform all updates/queries to Firestore stream directly
Firestore stays in synch all the time (??).
Any guidance on considerations for how to do this? Are there alternatives? Any references for me?
Thanks from the newbie:)

Only commit changes to Firestore on app/widget close

As Firestore charges by the read/write, it would be super helpful to keep the changes in memory during the session and only commit them when the user exists either the entire app or a specific section. Is there a way to do that in a Flutter web application?
I think one problem with this approach is that the user might just close the tab including your app. In this case, you have no time to send your data to Firestore.
This aside, you could use packages like Hive to store your documents offline and later run a function to add the data to Firestore later.
You also have 50k reads and 20k writes for free with Firebase, which is sufficient for smaller apps. If you exceed this limit, your app is probably big enough to earn money with it anyway.

Avoid fetching the same data from Firestore over and over again whenever the app starts

I am sorry, if it is a stupid question. I started to work with a Firestore db in a SwiftUI iOS App. Since I will be charged for every read/write/delete I try to avoid to read-in a snapshot with tons of documents (e.g. messages in a messenger app) every time the user starts the app.
I wondering what is the normal way to handle that? Do I have to write/save the messages locally into a sqlite or realm to fetch them at the next time from the internal db (on the Firestore side I create a query to read/load only documents that are newer than the last locally saved message)? Or does the Firestore (Firebase) has a built-in solution e.g. the cache?
I think you've already answered your question. You can save documents (messages) locally so you don't have to fetch them from Firestore every time (and only fetch the new ones). Firebase can cache data locally, but only temporarily. Saving the data using sqlite, realm, or even CoreData is a wise move.

My firestore account has A LOT of reads. How can I monitore from where?

My page is quite small it has around 300-1000 visits each day. But at some point I started to accumulate HUGE firestore read requests:
Till the 8th date it was somewhere around 50K each day. I am pushing new code all the time so I'm not sure what I did. Looking at the page I don't see anything out of ordinary. Is there some sort of log in google or firestore I could look at?
The Firebase documentation indicates that each time you create a project, it also creates a project in Google Cloud Platform, therefore you can track daily Cloud Firestore usage like writes, deletes, etc. This usage information is shown in the GCP's console in the App Engine Quotas page .You can see more details in the link. https://firebase.google.com/docs/firestore/monitor-usage#google-cloud-platform-console
There is currently no way to track the origin of reads. What you're looking at now is the best indicator you have available.
Bear in mind that the Firebase and Cloud consoles show updates to documents in real time, and each document update costs a read. If you leave the console open on a busy collection, it will rack up reads.

Is Firebase appropriate in pwa with offline mode?

I'm developing a PWA with Ionic/angular and Firebase/Firestore.
It manage a collection of categorized lyrics. Admins can add/delete/modify lyrics etc. Firestore is very usefull for that.
I want my PWA fully accessible offline after installation. To do that i need to read all collection (300 documents) when app loads in order to cache it. It is an important amount of reads by user, Google charge 300 reads each time app is loaded, and even more with listeners with database changes. I think, my use case is not very adapted to Firestore way to get data.
const lyricsCollection: AngularFirestoreCollection<Lyric> = this.afStore.collection<Lyric>('lyrics', ref => ref.orderBy('title'));
this.lyrics$ = lyricsCollection.snapshotChanges();
My question is: How can i improve my db or app architecture to be more adapted to my needs ?
Thanks