Question

I am trying to wrap my brain around NoSQL with Riak in particular. Looking at the CAP theorem, I have difficulty understanding how consistency takes place. Say, for example, I have an online shop. I have 6 items to sell. 2 people want to buy these items. The first person wants to buy 2 of these items while the second person wants to buy all 6 items. The two transactions take place almost immediately. How will this be done in such a way that the second person does not buy phantom goods?

I was thinking, off the top of my head, of using read/write locks. This might be a problem for availability I think.

I also saw something on Commutative Replicated Data Types. Still reading on journals about it but would anyone have any insight with regard to Riak?

Thank you in advance.

Was it helpful?

Solution

This problem is not specific to Riak or NoSQL, but with distributed systems in general. If you are using a relational database like mysql to track inventory, and are replicating that data between 2 or more servers, your application will need to be designed to ensure that you don't resell an item based on an availability report from server 2 when server 1 just processed a transaction selling the last one but it hasn't replicated yet. In either case you need to deal with locking or serializing purchase requests if you don't want to deal with apologizing to customers for shipping/production delays.

With Riak specifically, you can tune the availability/consistency to your needs through the use of read and write quorums, selectively failing operations like final purchase that must be consistent if the primary replicas are not available, while still allowing less critical operations like browsing inventory to continue. i.e. you can select consistency over availability or vice versa at query time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top