Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Realtime Database or Firestore for chatting app? [closed]

We are building a chat app, one-to-one chatting is the main purpose of the app so for now, messaging speed is our first priority. We need a backend solution and we were initially planning to use Firebase realtime database. But then Firestore came to existence, from there onwards we saw a lot of recommendations for Firestore over Realtime database from the Firebase team.

We have used both Realtime Database and Firestore so we are pretty aware of the capabilities and querying powers of both. For our use case in terms of features, any of them are fine. But as I told before our main concern is messaging speed. So which one is more realtime?

like image 756
Ajay Sivan Avatar asked Aug 01 '19 09:08

Ajay Sivan


People also ask

Should I use Firebase realtime database or firestore?

Primarily synchronizing data, with basic querying. If you don't need advanced querying, sorting and transactions, we recommend Realtime Database. Advanced querying, sorting, and transactions. If you need complex interactions with your data, for example in ecommerce apps, we recommend Cloud Firestore.

Is Firebase good for chat app?

Yes, in that it's easy to build a chat app on Firebase, and it's a really good showcase for the capabilities of real-time messaging and notifications. There's a reason it's one of the apps in the codelabs.

Can Firebase realtime database work offline?

By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache.

When should you not use firestore?

If you have a very time-sensitive app, like online auctions where you can't have unpredictable delays (no one likes to lose because of something that we don't control), you shouldn't really use Firestore.


2 Answers

So which one is more real-time?

I don't think one is more real-time than another.

But then Firestore came to existence, from there onwards we saw a lot of recommendations for Firestore

That's right, Firestore has some new features over Firebase Realtime Database, that's why is named "the new flagship". The query performance depends on the number of items you request and not on the number of items you request them from. So every time you think to get data, get it in such proportion to maintain the speed that you were talking about. As the guys from the Firebase team say, Cloud Firestore has a performance guarantee, there are no slow queries, so the time it takes your app to retrieve data depends on only on the amount of data you retrieve and not on the amount of data you have on Firebase servers. In other words, it doesn't matter if you have one thousand, one million, or even one billion documents within a single collection, retrieving for instance 15 of them, will always take the same amount of time.

This performance comes with some constraints and for that, I recommend you take a look at all sections within the official document regarding getting data in Cloud Firestore. That's the reason why Firestore uses those constraints, is due to the fact that is mandatory to maintain this performance guarantee. But from my experience, there is no "SQL" query that cannot be translated in a way or another in Cloud Firestore.

So remember, it really does not matter if you request a single document out of a 10 or one item out of 100.000 or 100.000.000.000, the result will come in the exact amount of time. Here I took as an example one document. So regarding speed, requesting one document out of 100 million will be faster than requesting 10 items out of the same 100 million. So the number of documents in the collection has no effect on the query performance.

This is about Cloud Firestore but there two main resources that I recommend you read before using one or another:

  • https://firebase.google.com/docs/database/rtdb-vs-firestore
  • https://firebase.googleblog.com/2017/10/cloud-firestore-for-rtdb-developers.html

So check the price models for each one of them. But IMHO, both Cloud Firestore and Firebase Realtime database work extremely fine together.

like image 200
Alex Mamo Avatar answered Oct 19 '22 05:10

Alex Mamo


In my opinion calculation is simple. Realtime database 10 000 M chat messages data transfer = $490. Firestore 5 000 M reads = $3000 and 5 000 M writes $9000 = $12000. So the cheapest way is to use realtime database and because of $5/GB stored you need each few weeks/months rewrite messages to firestore. For chat app like discord where you have conversation shared with many users the best way is to set a server witch different database like Cassandra.

like image 21
Mises Avatar answered Oct 19 '22 04:10

Mises