Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

distributed transactions and queues, ruby, erlang, scala

I have a problem that involves several machines, message queues, and transactions. So for example a user clicks on a web page, the click sends a message to another machine which adds a payment to the user's account. There may be many thousands of clicks per second. All aspects of the transaction should be fault tolerant.

I've never had to deal with anything like this before, but a bit of reading suggests this is a well known problem.

So to my questions. Am I correct in assuming that a secure way of doing this is with a two phase commit, but the protocol is blocking and so I won't get the required performance? I usually write Ruby, but it appears that DBs like redis and message queuing system like Rescue, RabbitMQ etc don't really help me a lot - even if I implement some sort of two phase commit, the data will be lost if redis crashes because it is essentially memory-only.

All of this has led me to look at erlang and scala - but before I wade in and start learning a new language, I would really like to understand better if this is worth the effort. Specifically, am I right in thinking that because of their parallel processing capabilities, these languages are a better choice for implementing a blocking protocol like two phase commit, or am I confused? And if yes, is there any reason to pick one rather than the other (specifically in this context - i know there are plenty of threads and blogs comparing the two more generally)

Apologies for cross posting - this was first posted to stack-exchange but I've added to the question and this version is probably a better fit here

like image 566
chrispanda Avatar asked Oct 13 '11 18:10

chrispanda


People also ask

What is a distributed transaction?

Transactions that span over multiple physical systems or computers over the network, are simply termed Distributed Transactions. In the world of microservices a transaction is now distributed to multiple services that are called in a sequence to complete the entire transaction. Here is a monolithic e-commerce system using transactions:

What's the problem with distributed transactions in microservices?

Because the transaction is now across multiple databases via multiple systems, it is now considered a distributed transaction. What’s the problem with distributed transactions in microservices? With the advent of microservice architecture we are losing the ACID nature of databases.

What is a a transaction in DBMS?

A transaction is a series of object operations that must be done in an ACID-compliant manner. The transaction is completed entirely or not at all. It is a term that refers to the transition from one consistent state to another. It is carried out separately from other transactions.

What is a a transaction in SAP?

A transaction is a series of object operations that must be done in an ACID-compliant manner. The transaction is completed entirely or not at all. It is a term that refers to the transition from one consistent state to another. It is carried out separately from other transactions. Once completed, it is long lasting. initiate a new transaction.


1 Answers

1) 2 phase commit is not fault tolerant - see the link. You either need a total order broadcast, or a non-blocking atomic commit, depending on the exact formulation of the problem you're solving.

2) I wouldn't say that Scala is much more suited than most other general purpose languages for implementing a two-phase commit. Specifically, STMs, parallel and distributed collections will not help you here. Scala actors and remote actors may provide you with a nice API to send messages around asynchronously (on the same machine or remotely), but they do not by default give you abstractions such as different failure detectors which would be useful for implementing total order broadcasts, for example - you'll still have to implement these yourself (on the other hand, I believe Akka has these abstractions).

3) I cannot speak for Erlang and Ruby, but as far as Scala and Java are concerned, you might want to consider taking a look at Akka. It is based on a distributed actor model, which also supports transactions and different levels of fault tolerance. It's probably better to reuse their infrastructure than writing your own distributed fault tolerant runtime from scratch.

like image 175
axel22 Avatar answered Sep 30 '22 18:09

axel22