Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing:
- 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.
- Cloud Firestore is Firebase's new flagship database for mobile app development. It improves on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales better than the Realtime Database.
Better querying and more structured data
Designed to Scale
Easier manual fetching of data
Multi-Region support for better reliability
Different pricing model
Cloud Firestore is a NoSQL, document-oriented database. Unlike a SQL database, there are no tables or rows. Instead, you store data in documents, which are organized into collections.
Cloud Firestore allows you to synchronize your database in near-realtime, enabling reactive apps, cross-device syncing, and cross-device collaboration.One of Google’s primary concerns with Cloud Firestore is having scalability, and aslo Google has aimed to make sure that query times scale with result sizes, not with the size of the overall database.
1.Data model: Both Realtime Database and Cloud Firestore are NoSQL Databases.
Realtime Database
Stores data as one large JSON tree.
- Simple data is very easy to store.
- Complex, hierarchical data is harder to organize at scale
Cloud Firestore
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.
2.Realtime and offline support: Both have mobile-first, realtime SDKs and both support local data storage for offline-ready apps.
Realtime Database
- Offline support for mobile clients on iOS and Android only.
Cloud Firestore
- Offline support for iOS, Android, and web clients.
3.Querying: Retrieve, sort, and filter data from either database through queries.
Realtime Database
Deep queries with limited
sorting and filtering functionality.
- You can only sort or filter on a property, not sort and filter on a property, in a single query.
- Queries are deep by default: They always return the entire subtree.
Cloud Firestore
Indexed queries with compound
sorting and filtering.
- You can chain filters and combine filtering and sorting on a property in a single query.
- Write shallow queries for subcollections: You can query subcollections within a document instead of an entire collection, or even an entire document.
- Queries are indexed by default: Query performance is proportional to the size of your result set, not your data set.
4. Writes and transactions:
Realtime Database
Basic write and transaction operations.
- Write data as an individual operation.
- Transactions in the native SDKs require a completion callback.
Cloud Firestore
Atomic write and transaction operations.
- Batch operations and complete them atomically.
- Transactions automatically repeat until they're completed.
5.Reliability and performance:
Realtime Database
Realtime Database is a mature product.
- Stability you'd expect from a battle-tested, tried-and-true product.
- Very low latency, so it's a great option for frequent state-syncing.
- Databases are limited to zonal availability in a single region.
Cloud Firestore
Cloud Firestore is currently in beta.
- Stability in a beta product is not always the same as that of a fully launched product.
- Houses your data across multiple data centers in distinct regions, ensuring
global scalability and strong reliability.
When Cloud Firestore graduates from beta, it will have stronger reliability than Realtime Database.
6.Scalability:
Realtime Database
Scaling requires sharding.
- Scale to around 100,000 concurrent connections and 1,000 writes/second in a single database. Scaling beyond that requires sharding your data across multiple databases.
Cloud Firestore
- Scales completely automatically (after beta), meaning you don't need to shard your data across multiple instances.
6. Security:
Realtime Database
Cascading rules that require separate validation.
- Firebase Database Rules are the only security option.
- Read and write rules cascade.
- You need to
validate data
separately using the
validate
rule.
Cloud Firestore
Simpler, more powerful security for mobile, web, and server
SDKs.
- Mobile and web SDKs use Cloud Firestore Security Rules. Server SDKs use Identity and Access Management (IAM).
- Rules don't cascade unless you use a wildcard.
- Data validation happens automatically.
- Rules can constrain queries: If a query's results might contain data the user doesn't have access to, the entire query fails.
7. Pricing: Both solutions are available on the Spark, Flame, and Blaze pricing plans.
Realtime Database
- Charges only for bandwidth and storage, but at a higher rate.
Cloud Firestore
- 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 Google App Engine projects, to make sure you don't go over the costs you're comfortable with.
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.
If you want to try out Cloud Firestore while it's in beta, use our
getting started guide.
To learn more about the features available on the Realtime Database, take a look at
the Realtime Database documentation.
No comments:
Post a Comment