Using Riak for Data with many Entities and Relationships
mtbrooks33 at gmail.com
Thu Feb 26 17:41:04 EST 2015
I am designing a web application that, for the purpose of this
conversation, deals with three main entities:
Users are members of groups, and tasks belong to groups.
Early in the development of the application, Neo4j was used to store the
data. Users would have a *MEMBER_OF *relationship to a group, and tasks
would have a *BELONGS_TO *relationship to a group. Neo4j was nice for
access control because I could add permissions to the MEMBER_OF
relationship. It was also nice for the simple BELONGS_TO relationship.
Neo4j separates entites and relationships nicely.
After reading about Riak and reminiscing about my use of MongoDB in the
past, I began to think about using Riak to store my data instead of Neo4j.
Storing the users, groups, and tasks seems trivial enough. But storing the
relationships seems a bit tougher.
I am planning on storing the entities in three buckets:
...where each of the buckets has the entity's ID as the key and a map of
the relevant information as the value.
What I am struggling with now is modeling the relationships I so easily
modeled in Neo4j, in Riak. I have a few ideas:
1. Store both user IDs and task IDs in lists inside of the group
information. The user ID list would also include permissions for the users.
2. Store group IDs in a list inside of the user information and task IDs
in a list inside of the group information.
3. Use a *user-group* bucket and a *group-task *bucket. The
*user-group *bucket will
have user IDs as the keys and a list of maps as the value. The maps in
question would hold a group ID and permission information for the group.
The *group-task *bucket would be similar to the *user-group *bucket, but
instead of a list of maps, it would simply have a list of task IDs.
4. Use Riak's links for both user membership and tasks belonging to
groups. A given user would have *member *links to groups, and a given
group would have *task *links to tasks. Permissions for a given user ID
would be stored in the group somewhere.
None of the four entirely satisfy me..
Number one makes it really *hard* and inefficient to ask the DB for the
groups that a user is a member of (I would have to go through every single
group and check if the user ID is in the member list). The same issue
occurs with tasks.
Number two makes it really *easy* to go from user to group to tasks, but
makes it difficult to go from group back to users. What if I wanted to
users are members of group X?"*.
Number three works in a way similar to relational databases, and does a
good job of separating relationships from entities. This has the same
issues mentioned in number two.
Number four seems to be the one that might be considered idiomatic Riak
usage, but we completely separate permissions from the *member*
relationship a user has with a group due to links not supporting complex
What do you think about the 4 models mentioned? Any ideas about how I can
model this data in Riak effectively?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the riak-users