Realtime Database vs Firestore [duplicate] - firebase

This question already has answers here:
What's the difference between Cloud Firestore and the Firebase Realtime Database?
(5 answers)
Closed 3 years ago.
I am building an app related to online bookings of Barbers in my city.I am planning to use Firebase to store my data and showing realtime updates. What will be the right option i.e. Realtime Database or Firestore. As much as I read, Firestore is great but it costs the developers according to number of queries and in my case query numbers will be much higher as I am planning to show realtime update to clients for their booking status.
And I am a naive in this area so suggest which one will be easy to learn.

It's up to you in the end, so I'll just name some main points:
Realtime Database is basically one giant JSON file, while Cloud Firestore is based on collections of documents.
Both offer realtime updating.
Cloud Firestore has better ways to filter and sort data.
Cloud Firestore has more advanced ways of writing and updating information.
Realtime Database is based on a single region, while Cloud Firestore can scale to multiple regions automatically.
They have different security options.
Realtime Database charges based on bandwidth and storage, but at a higher rate. As you mentioned in your question, Cloud Firestore charges based on operations on your database (read, write, etc.)
In the end, it all depends on how you want to work in your code. For example, do you want to work with one large JSON tree, or do you want to work with separate documents? Cloud Firestore is the newer of the two, but that doesn't necessarily mean it's better in your scenario.

Related

Using Firebase Realtime Database node keys as document ID's in Cloud Firestore

I am in the process of migrating my Realtime Database to Cloud Firestore. Ideally, I need to keep the same Realtime Database node keys that have been generated using push() and use it as the document ID in Firestore, but is this safe to do so?
I have read information at https://firebase.google.com/docs/firestore/best-practices and I am still unsure whether this will be safe. I am aware that auto generated document IDs in Cloud Firestore are in a different format to those automatically generated in Realtime Database.
Am I likely to run into problems by using by using Realtime Database generated keys such as: -M_NHw525_IxMqiGPUvd as the document ID in Cloud Firestore?
I really appreciate any help, Thanks.
Firestore is sensitive to hot spots in its writing process, meaning that write throughput is best when the writes are randomly distributed across the address space. In other words: if the IDs of the documents being written, and the values that are being written to the indexes, are randomly distributed.
Firebase Realtime Database push IDs start with an encoded timestamp, so they are definitely not randomly distributed. They are (by design) largely sequential: subsequent calls to push() typically leads to keys that are next to each other. This is exactly what they were designed for in Realtime Database, but it doesn't meet the requirement of a random distribution that is needed for maximizing write throughput in Firestore.
Whether you'll run into problems when using existing push keys for your Firestore writes really depends on the implementation. For example, during a data migration you'll want to be ready to throttle the writes (sooner) when they're not randomly distributed. Hopefully the above helps you to know what to keep an eye out for when performing the data migration.

Which firebase database to use for chat applicatoin, Firestore or Realtime Database?

I'm building an app which uses Firestore for storing most data. The app has a chat functionality and I was considering using Realtime Database for that. What are the benefits of using Firebase Firestore vs Realtime Database for this chat functionality? If there is no difference, should I use Firestore for everything?
P.S. I have already read the firebase comparison of the two https://firebase.google.com/docs/database/rtdb-vs-firestore and I am still not sure which way to go about this.
FB RTDB was designed for a chat application but is not so great for more than simple querying. Firestore was developed to improve the querying requirements and is newer. Newer doesn't necessarily mean better, depends on the use case. Their pricing models are very different, so you need to understand how your use case will be charged.
You can use both of course. They can work well together but if a simple chat requirement is all you need, I would use RTDB.
PS. The unique keys generated in RTDB for each new record are automatically in chronological order, which relates back to it being designed for a chat app. There is a caveat though, the chat messages may still get out of order because the keys are generated on the device and if the device clocks are slightly out and messages are being exchanged rapidly then you may get a miss timing. The way round this is to write each record with a property of server time...and use that to sort the chat messages. Hope that helps your decision.
PPS. RTDB charges for data storage volumes and data download volumes. Firestore charges for storage and db reads and writes. There will be a lot of the latter in a chat app so I would recommend running some what-if scenarios in Excel.

Cloud Firestore security rules with conditions from Firebase database

I had already saved all data like users or rooms contents on Firebase Database. Now I want to move all posts to Cloud Firestore for better queries.
But,
Can I take conditions from Realtime Database?
I mean all users data are in realtime database. So I want to get some informations from there, then decide whether it's accessible or not.
The security rule systems are different between Realtime Database and Firestore. There is currently no easy to way to simply copy from one to the other, or to make one recognize the other. If you're porting your data to Firestore, you'll have to write new rules by hand that functionally match the ones you were using in Realtime Database.
No, this isn't functionality that exists. You'll need to have migrated the data that the rules depend upon to Cloud Firestore first.

Can Firestore Scale

Can the new Firestore service scale?
I know it's in beta. I'm looking for some live examples of Firestore Scaling.
In terms of:
Number of database transactions.
Size of database.
Also - Does firebase have some auto scaling policy.
Can Firebase itself scales in terms of:
Number of users (using the OAuth)
Does anyone have some Firebase scaling example and could share.
firebaser here
The first line on the main documentation page for Cloud Firestore:
Use our flexible, scalable NoSQL cloud database to store and sync data for client- and server-side development.
A bit lower in key capabilities:
Designed to scale
Cloud Firestore brings you the best of Google Cloud Platform's powerful infrastructure: automatic multi-region data replication, strong consistency guarantees, atomic batch operations, and real transaction support. We've designed Cloud Firestore to handle the toughest database workloads from the world's biggest apps.
That tells you that the folks that created Cloud Firestore thinks that scalability is one of its key features. Give that these are the same folks that worked on many of Google Cloud Platform's features, I tend to believe them on that front. :-)
There were also some earlier questions that may be relevant:
What's the difference between Cloud Firestore and the Firebase Realtime Database?
Designed to Scale -- Cloud Firestore will be able to scale better than the Realtime Database. It's important to note that your queries scale to the size of your result set, not your data set. So searching will remain fast no matter how large your data set might become.
Queries scale with the size of your result set, not the size of your data set
Just keep in mind that Cloud Firestore is still in beta and will be slower (but scale better) than Firebase's realtime database:
Firestore slow performance issue on getting data

Firebase Firestore [duplicate]

This question already has answers here:
What's the difference between Cloud Firestore and the Firebase Realtime Database?
(5 answers)
Closed 5 years ago.
Recently Firebase Firestore was launched. After going through the documentation, I am confused how exactly Firebase Firestore is different Firebase Realtime Database and what are the situations in which Firestore should be used over Realtime Database as Realtime Database provides almost all the functionalites which Firestore provides (Querying, Security, Offline Capabilities).
In Realtime database of Firebase, it provides only the following features
Stores data as one large JSON tree.
Simple data is very easy to store.
Complex, hierarchical data is harder to organize at scale.
But in Firestone completely different data structure has been follow.
Stores data in documents organized in collections.
Simple data is easy to store in documents, which are very similar to JSON.
Complex, hierarchical data is easier to organize at scale, using subcollections within documents.
Requires less denormalization and data flattening.
For more detailing you can visit the following link: Difference between Realtime Vs Firestone

Resources