Say I have 100 products in inventory, instead of having a counter I want to
create 100 rows per inventory item.
When someone purchases a product, how can I correctly assign that customer
a product from inventory without having any race conditions etc?
Thanks.
S Ahmed 's gravatar image asked Nov 7 2016 at 11:51 in Cassandra-User by S Ahmed

3 Answers

You can use lightweight transactions to achieve this.
Example:
UPDATE item SET customer = 'Joe' WHERE item_id = 2 IF customer = null;
Keep in mind that lightweight transactions have performance tradeoffs (
http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0)
Justin Cameron
Senior Software Engineer | Instaclustr
This email has been sent on behalf of Instaclustr Pty Ltd (Australia) and
Instaclustr Inc (USA).
This email and any attachments may contain confidential and legally
privileged information. If you are not the intended recipient, do not copy
or disclose its content, but please reply to this email immediately and
highlight the error to the sender and then immediately delete the message.
Justin Cameron 's gravatar image answered Nov 7 2016 at 13:22 by Justin Cameron
Bear in mind that LWT will, under certain circumstances fail too. See
amazing Chris Batey's talk about it on Cassandra Summit:
https://www.youtube.com/watch?v=wcxQM3ZN20c
Carlos Alonso | Software Engineer | @calonso <https://twitter.com/calonso>
Carlos Alonso 's gravatar image answered Nov 8 2016 at 04:05 by Carlos Alonso
Hi,
can you elaborate a little your data model?
Would you like to create 100 rows for each product and then remove one row and add this row to customer?
Best regards, Vladimir Yudovin,
Winguzone - Hosted Cloud Cassandra
Launch your cluster in minutes.
Say I have 100 products in inventory, instead of having a counter I want to create 100 rows per inventory item.
When someone purchases a product, how can I correctly assign that customer a product from inventory without having any race conditions etc?
Thanks.
Vladimir Yudovin 's gravatar image answered Nov 8 2016 at 05:53 by Vladimir Yudovin