Riak newbie here :)

I'm building an application that among other things includes a traditional
Forum, kind of like phpBB.  I'm working on the data model and wondering how
to guarantee the uniqueness of a username when a new user registers an
account.

Of course, before saving a new username, I will first do a read to make
sure the key ( username ) is not found.

But, what I'm worried about is what happens if in between the time of the
read and the write, two separate users connected to different servers
(possibly geographically apart) try to register a new user with the same
username.

I see Riak has conflict resolution built in, but the default mechanisms
appear to favor the most recent update.

I actually want the reverse, I want to favor the oldest update.

It seems I could accomplish this by the following:

a) Set  allow_mult=true
b)  always pass in a timestamp
c)  Sleep 1 second for good measure
d) Do a read operation on the same key.  During conflicts, my client will
see multiple siblings.  My client can choose the oldest timestamp and
repost that one's X-Riak-Vclock to be the canonical one.

Now all this being said I have a couple of other options.

- For these kinds of essentially ACID -like operations (of which this is
really the only one I can think of in my whole application) I could use
another database such as Redis.

- Assuming N-Value is the default of 3, I could set R=3 and W = 3 on Reads
and Writes.  My understanding is that would help in some situations but
still doesn't really solve this issue (in terms of an atomic lock if you
will).

- Or, thinking about it more, the end user really won't have any idea that
they were the first or not to reserve that username.  This whole thing is
very edge case anyways, as 2 or more people would have
to independently choose the same username that was available less than a
second before.   I could just use Riak's default conflict resolution
(possibly even last_write_wins=true).   They would never know that I am
actually assigning the username to the most recent person, instead of first
person.  It strikes me as a little bit unfair in a way :)  Really it is
splitting hairs though.

But all this said I'd be curious on how people are handing these kinds of
things and if I'm thinking about this issue in a reasonable manner.
_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to