简体   繁体   中英

Storing transactions into a NoSQL Database

We are planning the next project and thinking about to store transactions into a NoSQL Database. 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.

So my question is this a good approach to handle that or should I just use a mysql database?

The problem why I was thinking about using noSQL is, that we assume there are a lot of queries in a short time.

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.

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 . 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.

  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. Please see the Applying the Saga Pattern talk for inspiration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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