实时数据库与Firestore

When it comes to cloud and database hosting, there are several options available for the developers such as Firebase, Firestore, AWS, Google Cloud and so on. If you are curious about Firebase vs AWS comparison, you can read this Firebase vs AWS article here.

对于云和数据库托管,开发人员可以使用多个选项,例如Firebase,Firestore,AWS,Google Cloud等。 如果您对Firebase与AWS的比较感到好奇, 可以在此处阅读此Firebase与AWS的文章

In this article, you’ll come across the major differences that can help you to figure out the better alternative — especially between Firebase and Firestore.

在本文中,您将遇到主要的差异,这些差异可以帮助您找出更好的替代方案,尤其是在Firebase和Firestore之间。

TL;DR

TL; DR

  • Cloud Firestore: It’s a Firebase new database that is used to build mobile apps. It has better scalability than a realtime database. Also, they have faster queries with richer features, etc.

    Cloud Firestore:这是Firebase的新数据库,用于构建移动应用程序。 它具有比实时数据库更好的可伸缩性。 此外,他们的查询速度更快,功能更丰富,等等。

  • Firebase Realtime Database: It’s an older and original database that will give you a low latency solution for mobile apps. It will sync your data instantly.

    Firebase实时数据库:这是一个较旧的原始数据库,它将为您提供针对移动应用程序的低延迟解决方案。 它将立即同步您的数据。

Now you might be thinking that both databases are good. So which should I go with? You can answer yourself once you know the major differences.

现在您可能会认为这两个数据库都很好。 那我应该去哪? 一旦知道主要差异,您就可以回答自己。

1.数据模型 (1. Data Model)

Doesn’t it sound like the Machine Learning Model? LOL. But it’s not. Sadly!

听起来像机器学习模型吗? 大声笑。 但事实并非如此。 真可悲!

The good news is that both have NoSQL databases. Find out more:

好消息是它们都具有NoSQL数据库。 了解更多:

  • Firebase Real-time Database: In Firebase Real-time Database stores data in a large JSON tree. That’s why small or simple data is easy to store. But complex and hierarchy based data is hard or organized when it’s scaled.

    Firebase实时数据库:在Firebase实时数据库中,将数据存储在大型JSON树中。 这就是为什么小的或简单的数据易于存储的原因。 但是,按比例缩放时,复杂或基于层次结构的数据很难或难以组织。

Image for post
  • Cloud Firestore: In Cloud Firestore, data is stored as a collection of documents. Small data is easy to store in documents that are pretty similar to JSON. On the other hand, Cloud Firestore complex and hierarchy based data is very easy to organize at scale. You can use subcollection in the documents. Cloud Firestore requires less normalization.

    Cloud Firestore:在Cloud Firestore中,数据存储为文档的集合。 小数据易于存储在与JSON非常相似的文档中。 另一方面,Cloud Firestore复杂且基于层次的数据非常易于大规模组织。 您可以在文档中使用子集合。 Cloud Firestore需要较少的规范化。

Image for post

2.实时和在线支持 (2. Real-time and Online Support)

Both the database supports offline mode (means support local storage) and supports real-time SDKs.

这两个数据库都支持脱机模式(意味着支持本地存储)并支持实时SDK。

  • Real-time Database: Offline support only for mobile (Android & iOS) devices.

    实时数据库:仅对移动(Android和iOS)设备提供脱机支持。

  • Cloud Firestore: Offline support for mobile (Android & iOS), web clients as well.

    Cloud Firestore:对移动设备(Android&iOS)和Web客户端的脱机支持。

3.在场 (3. Presence)

It can be very useful to gather the information that your client is online or not.

收集客户是否在线的信息可能非常有用。

  • Real-time Database: Real-time database records client connection status and provides us updates whenever the client connection is online or offline.

    实时数据库:实时数据库记录客户端连接状态,并在客户端连接在线或离线时向我们提供更新。

Cloud Firestore: Not supported natively. But that doesn’t mean you don’t have access to this feature. You can use real-time database support for presence, just syncing cloud Firestore and real-time database with the help of cloud functions.

Cloud Firestore:本机不支持。 但这并不意味着您无权使用此功能。 您可以使用实时数据库支持进行状态显示,只需借助云功能同步Cloud Firestore和实时数据库。

Related: How to Choose Between Firebase and CometChat Pro

相关如何在Firebase和CometChat Pro之间进行选择

4.查询 (4. Querying)

You can sort, retrieve and filter any kind of data from databases through queries.

您可以通过查询对数据库中的任何类型的数据进行排序,检索和过滤。

  • Real-time Database: You can use deep queries. But have some limitations on filtering and sorting the functionalities. You can use filter or sort on a property in your query but can not process both. By default, queries are deep and always return a complete subtree.

    实时数据库:您可以使用深度查询。 但是对功能进行过滤和排序有一些限制。 您可以对查询中的属性使用过滤器或排序,但不能同时处理两者。 默认情况下,查询很深,并且总是返回完整的子树。

Image for post
  • Cloud Firestore: You can use index queries with good compound filtering and sorting. You can use sorting, combine filtering and chain filter on every property in one single query. Here queries are light; they only return a document in the particular collection or the group of the collection but never return sub collection data. It means that Firestore Queries must return the whole document.

    Cloud Firestore:您可以将索引查询与良好的复合过滤和排序一起使用。 您可以在一个查询中对每个属性使用排序,组合过滤和链式过滤。 这里的查询很简单; 它们仅返回特定集合或集合组中的文档,而从不返回子集合数据。 这意味着Firestore查询必须返回整个文档。

Image for post

5.撰写和交易 (5. Writes and Transactions)

  • Real-time Database: Real-time database gives you a basic writes and transactions operation. Like writing data through the update and set operations. Here transaction is on specific data subtree.

    实时数据库:实时数据库为您提供了基本的写和事务操作。 就像通过update和set操作写入数据一样。 这里的事务在特定的数据子树上。

Image for post
  • Cloud Firestore: Cloud Firestore gives you advanced writes and reactions operations like writing data through the update and sets operations and you can use advanced transformation i.e., array and numeric operations, etc. Transactions can automatically write and read data from any part of your database.

    Cloud Firestore: Cloud Firestore为您提供高级写入和响应操作,例如通过更新和设置操作写入数据,并且您可以使用高级转换,即数组和数字操作等。事务可以自动从数据库的任何部分写入和读取数据。

6.可靠性和性能 (6. Reliability and Performance)

Reliability & performance are important parts where you can decide which database you want to choose.

可靠性和性能是重要的部分,您可以在其中决定要选择的数据库。

  • Real-time Database: It is a single region solution. In a single region, the database is limited to zonal availability. It provides a low latency. I think it’s an ideal option for the apps which use frequent syncing.

    实时数据库:这是一个单区域解决方案。 在单个区域中,数据库仅限于区域可用性。 它提供了低延迟。 我认为这是使用频繁同步的应用程序的理想选择。

  • Cloud Firestore: It is a multi-region solution, which means it scales automatically. Share your data across multiple data centers in separate regions just to make sure scalability is global and provides us strong reliability. It also provides regional and multi-regional configurations in the world.

    Cloud Firestore:这是一个多区域解决方案,这意味着它会自动扩展。 在不同区域的多个数据中心之间共享数据,只是为了确保可扩展性是全球性的,并为我们提供了强大的可靠性。 它还提供了世界范围内的区域和多区域配置。

Image for post

7.可扩展性 (7. Scalability)

  • Real-time Database: In real-time database, the scaling process is not automatic, we have to scale on your own. It scales around 200k connections simultaneously and gives you 1k writes per second in a single database. Real-time database gives you no limit on writes.

    实时数据库:在实时数据库中,扩展过程不是自动的,我们必须自行扩展。 它可以同时扩展约200k个连接,并在一个数据库中每秒提供1000次写入。 实时数据库使您不受写限制。

  • Cloud Firestore: In the Cloud Firestore Scaling process is automatic. Firebase does it on their own. In Cloud Firestore, it can be scaled over 1 million connections simultaneously and gives you 10k writes per second. And Firebase is going to increase this limit in the future. But the cloud Firestore has a limit on writes to every single document or index also.

    Cloud Firestore:在Cloud Firestore中,扩展过程是自动的。 Firebase自行完成。 在Cloud Firestore中,它可以同时扩展超过100万个连接 ,每秒可写1万次。 Firebase将来会增加此限制。 但是,云Firestore对每个文档或索引的写入也有限制。

8.安全性 (8. Security)

  • Real-time Database: Authorization and validation are separate. Write and read rules from the mobile SDKs which are secured by Firebase Real-time database rules. You can easily validate the data separately with the valid rules.

    实时数据库:授权和验证是分开的。 从移动SDK编写和读取规则,这些规则受Firebase实时数据库规则保护。 您可以使用有效规则轻松地分别验证数据

  • Cloud Firestore: Authorization and validation are combined. Write and read rules from the mobile SDKs which are secured by Firestore security rules. Here rules can restrict your queries because if a query’s result might be a kind of data that the user doesn’t have access to then the entire query fails.

    Cloud Firestore:将授权和验证结合在一起。 从移动SDK编写和读取规则,这些规则受Firestore安全规则保护。 这里的规则可以限制您的查询,因为如果查询的结果可能是用户无法访问的一种数据,则整个查询都会失败。

9.定价 (9. Pricing)

You can check out the pricing details from here Spark plan, Blaze plan, Flame plan.

您可以从此处查看Spark计划,Blaze计划,Flame计划的价格详细信息

  • Real-time Database: Firebase Real-time database charges only on Storage and bandwidth, which means other things are free. but I think storage and bandwidth charges are a little bit high.

    实时数据库: Firebase实时数据库仅按存储和带宽收费,这意味着其他事情都是免费的。 但我认为存储和带宽费用较高。

  • Cloud Firestore: Firebase cloud Firestore charges on your operations like read, delete & write and storage and bandwidth charges are low rather than Real-time database.

    Cloud Firestore: Firebase Cloud Firestore对您的操作(如读取,删除和写入以及存储)收取的费用和带宽费用较低,而不是实时数据库。

Image for post

In simple terms, if you are small scale go with Real-time or if you want to grow big, go with Cloud Firestore.

简而言之,如果您规模较小,请选择“实时”,或者如果要扩展,请使用Cloud Firestore。

哪个是赢家? (Which Is the Winner?)

I recommend you to go with Cloud Firestore.

我建议您选择Cloud Firestore。

The reason is pretty simple because it’s a new database and it is recommended by the Firebase team.

原因很简单,因为它是一个新数据库,并且是Firebase团队推荐的。

Moreover, Firestore gives you additional functionality, better performance, more robust security rules, and most importantly, it’s scalable.

此外,Firestore还为您提供了附加功能,更好的性能,更强大的安全规则,最重要的是,它具有可伸缩性。

At the end, please Subscribe to my newsletter to get more tutorials and tips on Android development directly in your inbox.

最后,请订阅我的时事通讯 ,直接在收件箱中获取有关Android开发的更多教程和技巧。

If you liked this article, you can read my new articles below:

如果您喜欢这篇文章,可以在下面阅读我的新文章:

Originally published at https://wajahatkarim.com on April 17, 2020.

最初于 2020年4月17日 发布在 https://wajahatkarim.com 上。

翻译自: https://android.jlelse.eu/realtime-database-vs-firestore-447b2d990599

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值