Transactions in NoSQL?

I am looking for NoSQL to scale alternatives to a database. What should I do if I want transactional things to be sensitive to such things?

+60
nosql transactions
Feb 06 '10 at 5:55
source share
11 answers

Generally speaking, NoSQL solutions have easier transactional semantics than relational databases, but still have capabilities for atomic operations at some level.

Typically, those that perform master-master replication provide less consistency and greater availability. Therefore, you need to choose the right tool for the right problem.

Many offer transactions at the level of one document (or series, etc.). For example, with MongoDB there is atomicity in one document, but documents can be quite rich, so this usually works very well - more info here .

+31
Feb 06 '10 at 19:35
source share

This is the closest answer I found that applies to any NoSQL database. This is on the 2007 blog from Adam Wiggins of Heroku.com:

An old example of using a database transaction to transfer money transfers from one bank account to another is a common bull. The correct solution is to save the list of events in the register (transfers between accounts) and show the current balance as the sum of the register. If you are programming in a functional language (or thinking this way), this is obvious.

From: http://adam.heroku.com/past/2007/12/17/a_world_without_sql/ (His site is great for ideas on scalability.)

I interpreted the above paragraph as follows:

  • Create a database for member accounts.
  • Create a message queue. The nickname is a "book."
  • Add in background workers to complete each request in the queue.

Additional Information. next in line / background workers: http://adam.heroku.com/past/2009/4/14/building_a_queuebacked_feed_reader_part_1/

The client (aka a participant or a client) performs the following steps to withdraw money:

  • Send a request for money.
  • The request is sent to the server.
  • The server queues it. This message is: "Withdraw $ 5,000."
  • The client displays: "Wait while the request is completed ..."
  • Client machines poll the server every 2 seconds, asking, "Is the request complete?"
  • On the server, background workers execute previous requests from other participants in first-to-first mode. In the end, they receive a customer request for money.
  • As soon as the request is completed, the client is assigned a message with a new balance.

You can use Heroku.com to quickly create a small layout if you are comfortable with Node.js or Ruby / Rack.

The general idea seems pretty simple and much better than using transactions baked into a database that make it super-hard to scale.

Disclaimer: I have not implemented this yet. I read about these things for curiosity, although I have no practical need for them. Yes, @gbn is right that a transactional DBMS is likely to be sufficient for the needs of Timmy and me. However, it would be interesting to see how far you can take NoSQL databases with open source tools and how to use a website called " A Tornado of Razorblades ".

+17
Aug 15 2018-10-18T00:
source share

I just wanted to comment on tips for dealing with money in this thread. Transactions are what you really want to use with money transfers.

In the example given, how to make translations very beautiful and neat.

But in real life, a money transfer may include fees or payments to other accounts. People receive bonuses for using certain cards that come from another account, or they can receive fees received from their account to another account in the same system. Fees or payments may vary depending on financial transactions, and you may need to maintain an accounting system that displays the credit and debit of each transaction as it arrives.

This means that you want to update more than one line at a time, since a loan on one account can be debited to one or more accounts. First, you lock the rows, so nothing can change before the update, then you will make sure that the data written corresponds to the transaction.

This is why you really want to use transactions. If something goes wrong by writing a single line, you can roll back a whole bunch of updates without the fact that the financial transaction data will not be contradictory.

+10
Nov 07. 2018-11-11T00:
source share

NoSQL covers a diverse set of tools and services, including repositories of keys, documents, graphs, and wide columns. They usually try to improve the scalability of the data warehouse, usually by disseminating data processing. The expected ACID properties of relational databases (which also determine the correct transactions) limit scalability: we must choose between non-scalability, consistency, or fault tolerance - and most of these tools refuse sequence and, therefore, ACID.

The most commonly cited theorem is the CAP theorem : consistency, accessibility, and admissibility of partitions cannot be achieved simultaneously. SQL, NoSQL, and NewSQL tools can be classified according to what they throw; You can find a good figure here .

A new, weaker set of requirements replacing ACID, BASE ("mostly avalilable, soft state, final consistency"). Ultimately, however, sequential tools ("ultimately all calls to the item will return the last updated value") are hardly acceptable for transactional applications such as banking. It would be nice to use column-based databases and distributed SQL / ACID databases, such as VoltDB ; I suggest taking a look at these NewSQL solutions.

+9
Aug 23 '12 at 16:39
source share

The problem with one transaction and two operations (for example, one paid $ 5,000, the second - $ 5,000) is that you have two accounts with the same priority. You cannot use one account to confirm the second (or in reverse order). In this case, you can guarantee that only one account will be correct (this will be confirmed), the second (confirmation) may be unsuccessful. Let's see why it can fail (using aproatch messages, the sender is acknowledged by the recipient):

  • Write + $ 5,000 to the beneficiary's account
  • If successful - write - $ 5000 to the sender's account
  • If it fails, try again or cancel or show the message

This guarantees retention for # 1. But who guarantees that No. 2 fails? Same for reverse order.

But it can be implemented to be secure without transactions and with NoSQL. You are always allowed to use a third organization, which will be confirmed by the sender and the recipient and ensures that your operation is completed:

  • Create a unique transaction identifier and create a transaction object
  • Write + $ 5000 to the beneficiary's account (with reference to the transaction identifier)
  • If successful, set the transaction status for sending
  • Write - $ 5000 for an account with an offline account (with reference to the transaction identifier)
  • If successful, set the transaction status to receive

This transaction record ensures that it is normal for a send / receive massage. Now you can check each message by transaction ID and, if it has a status, received or completed, you take it to your account for user balance.

+5
Apr 23 '12 at 7:50
source share

Depends on your DB, but ... I would say that in general you can use Optimistic Transactions to achieve this, but I imagine that you need to understand the atomicity database implementation guarantees (for example, what write and read operations are atomic).

There seems to be some online discussion about HBase if this is any help.

+1
Feb 06 '10 at 18:26
source share

In SQL DB, you can always use the NoSQL approach. Apparently, NoSQL usually uses β€œkey / value data stores”: you can always implement this in your preferred DBMS and therefore keep good things like transactions, ACID properties, support from your friendly database administrator, etc. etc., while realizing the benefits of NoSQL performance and flexibility, for example through a table such as

CREATE TABLE MY_KEY_VALUE_DATA ( id_content INTEGER PRIMARY KEY, b_content BLOB ); 

Bonus - you can add additional fields here to associate your content with other correctly relational tables, while maintaining your bulk content in the main BLOB field (or TEXT if apt).

Personally, I am in favor of introducing TEXT, so you are not tied to a language for working with data, for example. Using serialized Java means you can access content from Perl for reporting. TEXT is also easier to debug and, as a rule, work with the developer.

+1
Feb 23 '10 at 9:32
source share

Look at the scalar data: there is no sql db with strong consistency and implemented transactions.

+1
Jun 05 2018-12-12T00:
source share

That's why I am creating a NoSQL document repository solution for using "real" transactions in enterprise applications using the unstructured data method. Take a look at http://djondb.com and feel free to add any feature you think might be useful.

+1
Jul 06 2018-12-12T00:
source share

Of course there are others

+1
Jan 16 '13 at 8:51
source share

You can implement optimistic transactions on top of a NoSQL solution if it supports comparison and set. I wrote an example and some explanation on the GitHub page how to do this in MongoDB, but you can repeat it in any suitable NoSQL solution.

0
Oct 06
source share



All Articles