Question

I am counting posts and many other things on my website with counter column, I have a lot of traffic for example 10k+ comments per hour.

So what i want to achieve is once post is made and counter has been increased I would like to retrieve the exact value, but since there is high probability that two users going to requests that value at the same time i will get duplicates and that's bad.

Is there any way to retrieve exact value after increasing counter?

Was it helpful?

Solution

Cassandra's counters don't support the 'increment and get' semantics of general atomic counter implementations. So what you are asking is impossible with Cassandra's counters. The reason is that it would not be possible without coordination between the replicas to ensure values returned are always the latest.

To do this, you will need a distributed system with atomic semantics such as ZooKeeper. A thread that will solve your problem on ZooKeeper is here: http://www.mail-archive.com/zookeeper-user@hadoop.apache.org/msg01967.html.

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