tags:

views:

764

answers:

4

I'm looking into NoSQL for scaling alternatives to a database. What do I do if I want transaction-based things that are sensitive to these kind of things?

+1  A: 

Depends on your DB, but ... I would say in general, you can use 'Optimistic transactions' to achieve this but I imagine one should make sure to understand the database implementation's atomicity guarantees (e.g. what kind of write and read operations are atomic).

There seems to be some discussions on the net about HBase transactions, if thats any help.

Maxwell Troy Milton King
+3  A: 

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

Generally, the ones which do master-master replication provide less in the way of consistency, and more availability. So one should choose the right tool for the right problem.

Many offer transactions at the single document (or row etc.) level. For example with MongoDB there is atomicity at the single document - but documents can be fairly rich so this usually works pretty well -- more info here.

dm
+1  A: 

You can always use a NoSQL approach in a SQL DB. NoSQL seems to generally use "key/value data stores": you can always implement this in your preferred RDBMS and hence keep the good stuff like transactions, ACID properties, support from your friendly DBA, etc, while realising the NoSQL performance and flexibility benefits, e.g. via a table such as

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

Bonus is you can add extra fields here to link your content into other, properly relational tables, while still keeping your bulky content in the main BLOB (or TEXT if apt) field.

Personally I favour a TEXT representation so you're not tied into a language for working with the data, e.g. using serialized Java means you can access the content from Perl for reporting, say. TEXT is also easier to debug and generally work with as a developer.

Brian
+1  A: 

This is the closest answer I found which would apply to any NoSQL database. It's on a 2007 blog post from Adam Wiggins of Heroku.com:

The old example of using a database transaction to wrap the transfer of money from one bank account to another is total bull. The correct solution is to store a list of ledger events (transfers between accounts) and show the current balance as a sum of the ledger. If you’re programming in a functional language (or thinking that way), this is obvious.

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

I interpreted the above paragraph as:

  1. Create a database for member accounts.
  2. Create a messaging queue. Nickname it "ledger".
  3. Add in background workers to fulfill each request in the queue.

More info. on queues/background workers: http://adam.heroku.com/past/2009/4/14/building_a_queuebacked_feed_reader_part_1/

The client (aka member or customer) follows these steps to take out money:

  1. Submit a request to take out money.
  2. Request is sent to server.
  3. Server places it in a queue. The message is: "Take out $5,000."
  4. Client is shown: "Please wait as request is being fulfilled..."
  5. Client machines polls server every 2 seconds asking, "Has the request been fulfilled?"
  6. On server, background workers are fulfilling previous requests from other members in first-in/first-out fashion. Eventually, they get to your client's request to take out money.
  7. Once request has been fulfilled, client is given a message with their new balance.

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

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

Disclaimer: I haven't implemented this in any way yet. I read about these things for curiosity even though I have no practical need for them. Yes, @gbn is right that a RDBMS with transactions would probably be sufficient for the needs of Timmy and me. Nevertheless, it would be fun to see how far you can take NoSQL databases with open-source tools and a how-to website called, "A Tornado of Razorblades".

da01
Seems to be a strange criticism to the "hello world" example for transactions. What happens if during creation of one of the "ledger events" something fails? Then the balance for that account would be wrong. This does not sound like a workable replacement for transactions to me.
a_horse_with_no_name