On Jan 29, 2014, at 5:48 AM, Benoit Chesneau <[email protected]> wrote:

> I wonder if someone already thought to implement distributed counters using
> couchdb? 

Quick and dirty idea: Implement the counter as a document storing a map from 
UUIDs to deltas (1 or -1). To modify the count, add a new UUID key whose value 
is the amount to increment/decrement by. The value of the counter is the sum of 
all the increment values. When there's a conflict, just merge together the two 
documents keeping all key/value pairs that occur in either map.

You can store more info if you want by using something descriptive in place of 
the UUID, for example a username+timestamp. Just as long as it's guaranteed to 
be unique.

—Jens

Reply via email to