Forum: Building VoltDB Applications

Post: Is it possible to design a single partition transaction for money-transfer like appl

Is it possible to design a single partition transaction for money-transfer like appl
paul
Jan 4, 2011
Imagine a Paypal like application that allows users to transfer money between each others. Is it possible to design a single partition transaction for that purpose? Let's say that we have the following table for users,

create users(
id BigInt unique not null, /*partition*/
dollarsIhave BigDecimal,
primary key (id)
);


and the partition col is "id". If "id1" transfers $10 to "id2", it seems that no matter what, one can not avoid using a multi-partition procedure to update the cols "dollarsIhave" for the two users. Is this true that for such an application, multi-partition transaction is unavoidable?

Of course one can put all users in a single partition, but let's assume that there are a large number of users and we do want to partition somehow to scale out.
re: money transfer like application
tcallaghan
Jan 6, 2011
Paul,

You are correct in your conclusions.

If you create a VoltDB instance with 1 unique partition, then every transaction will be single-partition. You'll still need to annotate your stored procedures as single-partition and list your tables as partitioned in your project.xml file. In this scenario you can have additional nodes for k-safety, but you will be bounded the the performance capability of a single partition. I've benchmarked applications capable of performing 50,000+ transactions per second in this configuration.

The alternative is that your "money transfer" transactions need to be two single-partition stored procedures. You could fire them back to back or have the second execute in the callback from the first.

-Tim
Tim - Thanks. Executing the
paul
Jan 7, 2011
Tim - Thanks. Executing the second in the callback of the first is a good idea. So if the first failed, we are ok since the second one will not be executed. What to do if the first succeeds but the second one fails? Write to an error log and recover manually later? For paypal like applications, this approach seems ok if one takes money out of an account first.
re: money-transfer
tcallaghan
Jan 7, 2011
Tim - Thanks. Executing the second in the callback of the first is a good idea. So if the first failed, we are ok since the second one will not be executed. What to do if the first succeeds but the second one fails? Write to an error log and recover manually later? For paypal like applications, this approach seems ok if one takes money out of an account first.


Paul,

You will receive a callback from the second transaction on success and failure, if it fails you can choose what to do. If possible you may want to re-attempt transaction 2, or you could call a reversing transaction for the first.

-Tim
re: money-transfer
alex
Dec 29, 2011
Paul,

You will receive a callback from the second transaction on success and failure, if it fails you can choose what to do. If possible you may want to re-attempt transaction 2, or you could call a reversing transaction for the first.-Tim


Hi Tim,

Where does the callback go if your application fails before the procedure returned from transaction 1?

Does it go to:
- a nominated other node
- a random node
- nowhere
- other

Or would failure to callback trigger some kind of roll back? In which case, if the application failed after the first completed succesfully but beofre the second transaction then do we still have a atomicity problem?

Thanks
Hi Al, If the application
aweisberg
Dec 29, 2011
Hi Tim,

Where does the callback go if your application fails before the procedure returned from transaction 1?

...


Hi Al,

If the application fails the callback goes nowhere.

To get what people usually call transactions you need isolation and atomicity.

Isolation can be achieved through a combination of locking and multi version concurrency control.

Atomicity can be achieved via undo or redo logging.

I have been working on an example of how to do that with row level locking and a redo log. See https://github.com/VoltDB/voltdb/blob/kv_txns/examples/voltkv/src/voltkv/KVStore.java

Ariel