educative.io

How and where do we generate sequence number with every message for each client?

How and where do we generate sequence number with every message for each client?

AFAIK HBase doesn’t provide such functionality as incrementing, also it’s not appropriate to do this on UI side as user can use 2 different clients simultaneously.

How do we do it in a right way?

Hi Pavel.

We don’t need an auto-incrementing key (which is not supported in HBase), we only need an auto-incrementing counter. There can be many ways to do this, we can use HBase’s counters:

https://groups.google.com/forum/#!topic/opentsdb/1iXPUIUZmw8

Even in this case we can use some client side counter. The problem you mentioned with client side counters is correct, but if you see closely, it is the same problem as with two users sending messages (i.e., our original problem). So if a user sends two message simultaneously from two different clients, one of them will win (the race condition) and we have to live with this. As we are only storing the sequence per user (and not per client).

Hope this helps.