Link walking with Erlang riak client

Eric Moritz eric at themoritzfamily.com
Tue Jun 19 13:48:49 EDT 2012


Links may not be the most appropriate way to model a set of associated
users.  They have a limited length and both the user data and the
links have to be saved at the same time.

What you can do is emulate a set using a separate bucket and secondary indexes.

So basically the bucket would look like this:

So if I'm a friend of yours,

PUT /buckets/friends/keys/eric-morgan
x-riak-index-friend_id_bin: morgan
x-riak-index-user_id_bin: eric
Content-Type: application/json

{"user_id": "eric", "friend_id": "morgan"}

Then you can fetch a set of my friends by doing a 2i query for the
bucket friends and the index
user_id.

If you want to a set of all the people that have friended you, do a 2i
query on friend_id with the value "morgan".

You can quickly see if we're mutual friends by fetching:

/buckets/friends/keys/eric-morgan and /buckets/friends/keys/morgan-eric.

If both are found, then we're mutual friends.

Eric.

On Tue, Jun 19, 2012 at 12:35 PM, Morgan Segalis <msegalis at gmail.com> wrote:
> Hi everyone !
>
> I'm looking for a NoSQL solution to get ride of MySQL.
> In this particular issue, I think that Riak is one of the top of my choices in order to do what I'm looking for.
>
> I would like to store all my users into Riak.
> I understand that Riak is document oriented, so that's great for getting every information really fast from one user.
> One of the feature I'm really interested in, are Links.
>
> Links seems to be a great way for me to create association between users…
>
> When A adds B, I create a link from A to B.
> When B accepts A's invitation, I create a link from B to A.
>
> If links are not both ways, e.g. A to B to A, message can not go through (B who didn't accept A should not get its message yet)
>
> My server is coded in Erlang, I have checked the Erlang riak client, and I didn't see something as simple as the HTTP use of Links in the demo.
>
> 1 - Are Link walking in Erlang fast & easy ?
> 2 - Is it possible to check fast if A -> B -> A (still in Erlang)? ('->' represents Links)
>
> Thank you for your help !
>
> Morgan.
> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com




More information about the riak-users mailing list