Choose a database: Cloud Firestore or Realtime Database
https://firebase.google.com/docs/firestore/rtdb-vs-firestore
Choose a database: Cloud Firestore or Realtime Database
Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing:
Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales further than the Realtime Database.
Realtime Database is Firebase's original database. It's an efficient, low-latency solution for mobile apps that require synced states across clients in realtime.
Which database does Firebase recommend?
Your choice of database solution will depend on many factors, but when it comes to certain features, we can make recommendations about which database is right for you.
Both solutions offer:
- Client-first SDKs, with no servers to deploy and maintain
- Realtime updates
- Free tier, then pay for what you use
Key considerations
Beyond great core features common to both databases, think about how any or all of the considerations listed below will affect the success of your apps.
Role of the database | My app uses a database for... |
Operations on data | My app's database usage looks like... |
Data model | I prefer to structure my data as... |
Availability | My availability needs are... |
Offline queries on local data | My app will need to perform queries on devices with limited or no connectivity... |
Number of database instances | In my individual projects, I need to use... |
What are some other important things to consider?
After thinking about the previous key considerations, you might be ready to choose a database. If you're still weighing pros and cons, this section covers other differences between Cloud Firestore and Realtime Database.
Data model
Both Realtime Database and Cloud Firestore are NoSQL Databases.
Realtime Database | Cloud Firestore |
---|---|
Stores data as one large JSON tree.
Learn more about the Realtime Database data model. | Stores data as collections of documents.
Learn more about the Cloud Firestore data model. |
Realtime and offline support
Both have mobile-first, realtime SDKs and both support local data storage for offline-ready apps.
Realtime Database | Cloud Firestore |
---|---|
Offline support for Apple Android clients. | Offline support for Apple, Android, and web clients. |
Presence
It can be useful to know when a client is online or offline. Firebase Realtime Database can record client connection status and provide updates every time the client's connection state changes.
Realtime Database | Cloud Firestore |
---|---|
Presence supported. | Not supported natively. You can leverage Realtime Database's support for presence by syncing Cloud Firestore and Realtime Database using Cloud Functions. See Build presence in Cloud Firestore. |
Querying
Retrieve, sort, and filter data from either database through queries.
Realtime Database | Cloud Firestore |
---|---|
Deep queries with limited sorting and filtering functionality.
| Indexed queries with compound sorting and filtering.
|
Writes and transactions
Realtime Database | Cloud Firestore |
---|---|
Basic write and transaction operations.
| Advanced write and transaction operations.
|
Reliability and performance
Realtime Database | Cloud Firestore |
---|---|
Realtime Database is a regional solution.
| Cloud Firestore is a regional and multi-region solution that scales automatically.
|
Scalability
Realtime Database | Cloud Firestore |
---|---|
Scaling requires sharding.
| Scaling is automatic.
|
Security
Realtime Database | Cloud Firestore |
---|---|
Cascading rules language that separates authorization and validation.
| Non-cascading rules that combine authorization and validation.
|
Pricing
Both solutions are available on the Spark and Blaze pricing plans.
Realtime Database | Cloud Firestore |
---|---|
Charges only for bandwidth and storage, but at a higher rate. Read more about Realtime Database pricing plans. | Charges primarily on operations performed in your database (read, write, delete) and, at a lower rate, bandwidth and storage. Cloud Firestore supports daily spending limits for App Engine projects, to make sure you don't go over the costs you're comfortable with. Read more about Cloud Firestore pricing plans. |
Using Cloud Firestore and Realtime Database
You can use both databases within the same Firebase app or project. Both NoSQL databases can store the same types of data and the client libraries work in a similar manner. Keep in mind the differences outlined above if you decide to use both databases in your app.
Learn more about the features available in both Realtime Database and Cloud Firestore.
Ready to choose a database?
Hopefully this comparison has helped you settle on a Firebase database solution. Now you can learn how to add a database to your Firebase projects.
No comments:
Post a Comment