How to organize nodes in a graph database

We're building a graph database, and we're wondering how to model the graph structure. The idea is having users who can relate to several things (friends, posts in blogs, etc). Our doubt is if it's better having intermediate nodes like this:

User1 -+-> Friends -+-> User2
       |            |
       |            +-> User3
       |
       +-> Posts -+-> Post1
                  |
                  +-> Post2

Or if you would connect directly the user with the items he owns, like this:

User1 -+-> User2
       |
       +-> User3
       |
       +-> Post1
       |
       +-> Post2

We see benefits and problems with both styles. It would be great for us to hear opinions of people with more experience working with social graphs.

Upvotes: 3

Views: 546

Answers (1)

Mattias Finné
Mattias Finné

Reputation: 3054

the first thing that comes to mind is that if you have many (thousands or more) relationships of different types you'll run into a current issue with loading relationships for a node (if it isn't loaded into cache yet) where all have to be loaded even if you only would like to get some relationships of a specific type. This loading issue will be addressed rather soon I think.

Another thing you could keep in mind is that friends may not be very many, although posts will and having all posts connected directly to the user will have you run into the issue of sorting too when the number of posts increases. That's why I'd suggest you to put posts in a linked list on the user, with the most recent first. This will make them naturally sorted by date, like:

User -+-> Post3 --> Post2 --> Post1
  |
  +-> User2
  |
  --> User1

Upvotes: 2

Related Questions