using g-counter for sequence number synchronization

Christopher Meiklejohn cmeiklejohn at
Mon Jan 26 03:56:26 EST 2015

> On Jan 23, 2015, at 5:32 PM, Hristo Asenov <hristo.s.asenov at> wrote:
> Hello everyone,
> I have noticed that in latest documentation on Riak data types ( <>), for Counters it is not recommended to use them for ordered IDs (UUIDs). Can I implement g-counters (as described in the CRDT paper) using Riak’s Set datatype? I am wondering whether that will work out well for my use case.
> What I would like to do is to have synchronization of sequence numbers between multiple src processes that send their inputs to a single centralized process. I want all the sequence numbers to be unique so that the centralized process can create an ordering of the input messages based on the sequence numbers. Thus I would have an integer entry for each src process in the set, and the sum of all the integers would be my unique id. After the src process writes a value to the DHT for its corresponding entry, would it then have to read the value from the DHT in order to make sure it got committed without conflicts?

Hi Hristo,

I’m not sure if I completely followed your use case, but I believe that you probably want strongly consistent operations if you want to generate a total order over a series of operations.

Using the sum of the integers of a G-Counter (or a G-Counter built on Riak’s set data structure) does not guarantee a globally unique number; given these counters are designed (and therefore allowed) to diverge, imagine the following scenario, possible due to delays in replication:

Replica A, G-Counter:
[{pid1, 2}, {pid2, 1}], Sum: 3

Replica B, G-Counter:
[{pid1, 1}, {pid2, 2}], Sum: 3

These both share the same sum, but should represent unique operations, right?  Did I understand correctly?

- Chris

Christopher Meiklejohn
Senior Software Engineer
Basho Technologies, Inc.
cmeiklejohn at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the riak-users mailing list