FireStore UI showing old data while Backend is up to date - firebase

All of a sudden after deleting a collection Firestore started bugging.
Firebase web console is showing old data while the code running on my test server is showing new data, received from a tradingview(webhook).
LOGIC
each time there is a new trade signal. data is stored in Firestore and a client retrieves the data with a data listener. So I know if the data is new or old.
UnSYC screenshots
== FIRST PROOFS ==
proof signal is sent
proof signal is stored in firestore db
proof firestore db UI is not synced
== SECOND PROOFS ==
proof signal is sent again
proof signal is stored in firestore db again
proof firestore db UI is not synced again

Related

Will firebase be able to handle huge traffic?

So I have been coding a realtime chat app with flutter and firebase. Apparently there is a simultaneous concurrent connection limit of 200k on the RTDB, if my app reaches these limits, firebase suggests that I shard my database.
The problem with that is, that I cannot completely separate data from one database instance to another, as it's a realtime social media app, and one user should be able to access other user's information such as name, bio etc.
What I want to know is that, should I stick with firebase for this, or should I go with some other database.
You can always access data from multiple shards on your app as long as you know which shard does the required data belong to. You can also use Firestore along with Realtime database to suit your needs. Checkout the following answer for an example:
How to shard data Realtime Database for chat app?
This stores all user profiles and basic information about the chats (including which shard is the conversation stored in) which makes it easier to query list of chats of a particular user(s) from Firestore and then read messages from realtime DB.

Flutter: Minimising Firestore read/write operations

I am new to Flutter and mobile development in general and currently trying to wrap my head around certain database principles. I am building an note-taking app which uses Firestore for storing note data to the cloud. Users first need to register an account and log in, after which they are able to view and store notes to the cloud. The way I initially designed this was by using StreamProvider connected to the Firestore instance to update the user's list of notes after they add a note to their list.
After some reflection and worries that my app would be 'read' intensive, I realised that what I am trying to build does not require the notes to be constantly fetched from the server, as the data is private to them and should only be fetched by the user that creates it. My solution is instead of creating notes and listening to changes on the Firestore server to update the list, when a user creates a new note, a function should run and update the Firestore server as well as a local nosql database, removing the need for a read operation on the server after writing to it. This would allow me to have a local duplicate copy of the Firestore server and to periodically update it with write operations when needed. The only read operation would be on the app's startup to fetch a copy of the Firestore server.
My questions are:
Is storing a local version of the Firestore server a viable solution to minimise the number of read operations in my app, or am I overcomplicating things?
The StreamProvider allowed me to easily access data relating to the user, notes, etc throughout the app using Provider.of<Model>(Context). How can I easily access this data regardless of where I am in the app?
Given that my Firestore database structure for accessing notes is users/{user.id}/notes/{note.id}/note , how can I get a snapshot of the current logged in user ID and all the child fields in a single request (i.e. all the user's notes in users/{user.id}/notes and user data under users/{user.id}/)

Firestore + Ionic Angularfire Read Count & Cache Persistent

I'd like to use Ionic 4 + Firestore to provide app with offline and live sync capability.
Target deploy to Native App (iOS, Android), electron App (Windows and Mac), PWA.
Is firestore local cache persistent in hybrid app?
What type of storage firestore cache using?
Will it be something like localstorage, which will be delete by android / iOS from time to time / while low storage.
I'm testing with below code and did enablePersistence, offline mode is working just fine.
But it seem that the the it count all documents read per app launch.
Example, I'm having 100 documents.
a. While app first launch, it should count as 100 read as it sync all data to local cache.
b. While 2nd time I launch the app, assume, no document was updated, it shouldn't count any read right?
c. Because from my monitoring, the read count increase every time I launch the app.
d. Will it be any possible like, no document was updated, but my code force to fetch data from server then it consume the read count?
Thanks.
getChatMessages(groupId) {
return this.db.collection(`groups/${groupId}/messages`, ref => ref.orderBy('createdAt')).snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
}))
);
}
I guess you are talking about the offline data, I think your question can be answered with the docs.
1.1. Is firestore local cache persistent in hybrid app?
It should since the functionality comes with the client libraries that you should be using into your hybrid app.
From this doc:This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. YES, it’s local storage.
1.2. What type of storage firestore cache using?
From this doc: Cloud Firestore is a cloud-hosted NoSQL database. You store data in documents, which contain fields mapping to values.
2. a - You stated: “While app first launch, it should count as 100 read as it sync all data to local cache”, but as mentioned above, Firestore will only load the data that your app is using actively, so mostly your are seeing a subset of your total data (100 documents).
b- Regarding your claim about assuming no document modification, anyway your app will sync the data, which already means a validating request. At this doc it’s stated:
The Cloud Firestore client library automatically manages online and offline data access and synchronizes local data when the device is back online.
c- This claim is correct and points to the sentence I pointed before.

Improper data returned by reference.on('value') in firebase web api

When using firebase realtime database Node API (import "firebase-admin"), improper values (empty updates) are randomly delivered via query.on('value') as the initial update.
I rely proper data being delivered from the very first update. The reason why I'm using .on('value') is code reuse, in other places that require the data stream.
What is the contract on the data updates in firebase?
If I switch to .once('value') does it change the contract?

Firestore pricing clarifications for offline cached data

It seems odd to me that Firestore would charge me for read queries to locally cached data, but I can't find any clarification to the contrary in the Firestore Pricing document. If I force Firebase into offline mode and then perform reads on my locally cached data, am I still charged for each individual entity that I retrieve?
Second, offline users in my app write many small updates to a single entity. I want the changes to persist locally each time (in case they quit the app), but I only need eventually consistent saves to the cloud. When a user reconnects to the internet and Firestore flushes the local changes, will I be charged a single write request for the entity or one per update call that I made while offline?
Firestore could potentially fit my use case very well, but if offline reads and writes are charged at the same rate as online ones it would not be an affordable option.
As the offical documentation says,
Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data. When the device comes back online, Cloud Firestore synchronizes any local changes made by your app to the data stored remotely in Cloud Firestore.
So, every client that is using a Firestore database and sets PersistenceEnabled to true, maintains it's own internal (local) version of the database. When data is inserted/updated, it is first written to this local version of the database. As a result, all writes to the database are added to a queue. This means that all the operations that where stored there will be commited on Firebase servers once you are back online. This also means that those operations will be seen as independent operations and not as a whole.
But remeber, don't use Firestore as an offline-only database. It is really designed as an online database that came work for short to intermediate periods of being disconnected. While offline it will keep queue of write operations. As this queue grows, local operations and app startup will slow down. Nothing major, but over time these may add up.
If Google Cloud Firestore priceing model does not fit your use case very well then use Firebase Realtime Database. As mentioned also in this post from the Firebase offical blog, one the reasons you still might want to use the Realtime Database is:
As we noted above, Cloud Firestore's pricing model means that applications that perform very large numbers of small reads and writes per second per client could be significantly more expensive than a similarly performing app in the Realtime Database.
So it's up to you which option you choose.
According to this If you want to work completely offline with Cloud Firestore you can disable network by :
FirebaseFirestore.getInstance().disableNetwork()
but firestore will cause client offline error for first user get request, that you must consider this error as empty response.

Resources