简体   繁体   English

将事务存储到 NoSQL 数据库中

[英]Storing transactions into a NoSQL Database

We are planning the next project and thinking about to store transactions into a NoSQL Database.我们正在规划下一个项目并考虑将事务存储到 NoSQL 数据库中。 Basically it is an application where the user can collect some points (like payback) and later pay with points.基本上它是一个应用程序,用户可以在其中收集一些积分(如回报),然后用积分支付。

The main idea was to store the transactions itself into the noSQL Database and mysql server only stores the current balance.主要思想是将交易本身存储到 noSQL 数据库中,而 mysql 服务器仅存储当前余额。

So my question is this a good approach to handle that or should I just use a mysql database?所以我的问题是这是一个很好的处理方法,还是我应该只使用 mysql 数据库?

The problem why I was thinking about using noSQL is, that we assume there are a lot of queries in a short time.我考虑使用 noSQL 的问题是,我们假设在短时间内有很多查询。

Using polyglot persistence increases the operation load, so if it's possible to solve the task with one data store then it's better not to introduce additional entities.使用多语言持久性会增加操作负载,因此如果可以使用一个数据存储解决任务,那么最好不要引入额外的实体。

In your case it seems that you want to have auditable transaction history, consistent current balance and you don't want to abandon the transaction guarantees.在您的情况下,您似乎希望拥有可审计的交易历史记录、一致的当前余额并且您不想放弃交易保证。 It's true that almost all modern NoSQL solution don't support ACID transactions out of the box, but most of them support primitives which allow you to implement transactions on the application level.确实,几乎所有现代 NoSQL 解决方案都不支持开箱即用的 ACID 事务,但它们中的大多数都支持允许您在应用程序级别实现事务的原语。

If a data store supports per key linearizability and compare-and-set (document level atomicity) then it's enough to implement client-side transactions, more over you have several options to choose from:如果数据存储支持每个键的线性化和比较和设置(文档级原子性),那么实现客户端事务就足够了,此外,您还有几个选项可供选择:

  1. If you need Serializable isolation level then you can follow the same algorithm which Google use for the Percolator system or Cockroach Labs for CockroachDB .如果您需要 Serializable 隔离级别,那么您可以遵循 Google 用于Percolator系统或 Cockroach Labs 用于CockroachDB的相同算法。 I've blogged about it and create a step-by-step visualization , I hope it will help you to understand the main idea behind the algorithm.我已经写了一篇关于它的博客并创建了一个逐步的可视化,我希望它会帮助你理解算法背后的主要思想。

  2. If you expect high contention but it's fine for you to have Read Committed isolation level then please take a look on the RAMP transactions by Peter Bailis.如果您预计会出现高争用,但拥有 Read Committed 隔离级别对您来说没问题,那么请查看 Peter Bailis 的RAMP 事务

  3. The third approach is to use compensating transactions also known as the saga pattern.第三种方法是使用补偿事务,也称为传奇模式。 It was described in the late 80s in the Sagas paper but became more actual with the raise of distributed systems.它在 80 年代后期的Sagas论文中有所描述,但随着分布式系统的 兴起而变得更加实际。 Please see the Applying the Saga Pattern talk for inspiration.请参阅应用 Saga 模式演讲以获取灵感。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM