Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to implement Multi-Version Concurrency Control (MVCC) on top of MongoDB?

MongoDB is to me a great database. However there are cases where I really need atomic multi-document transactions. For example to transfer things (like money or reputation) between accounts and this needs to either succeed completely or fail completely.

I wonder if it would be possible to interact with MongoDB through a library implementing the MultiVersion Concurrency Control pattern.

How bad would it be concerning performances? Would it be possible and profitable to use a hybrid approach, using the 'mongo-mvcc' library only when necessary and the traditional db connection when working only on a single document or would this break the mvcc stuff ?

like image 886
ascobol Avatar asked May 12 '11 21:05

ascobol


4 Answers

The simplest way is to use locks (two-phase commit), although this is not very efficient in some cases. For higher concurrency some kind of MVCC can be implemented on the top of Mongo. This article provides a good description:

http://highlyscalable.wordpress.com/2012/01/07/mvcc-transactions-key-value/

like image 68
user1128016 Avatar answered Nov 24 '22 00:11

user1128016


Money transaction can be implemented via two-phase commit : http://www.mongodb.org/display/DOCS/two-phase+commit

like image 22
fun_vit Avatar answered Nov 24 '22 00:11

fun_vit


There is an implementation of MVCC on MongoDB available now on GitHub:

https://github.com/igd-geo/mongomvcc

like image 42
Thorsten Reitz Avatar answered Nov 24 '22 01:11

Thorsten Reitz


MongoDB isn't really designed to work with transactions. There is a really good discussion of how you might be able to implement this over at: http://kylebanker.com/blog/2010/04/30/mongodb-and-ecommerce/

like image 39
Leonard Garvey Avatar answered Nov 24 '22 02:11

Leonard Garvey