Colin M
Colin M

Reputation: 13328

Graph Database for Users

In my application, I need users to be assigned to groups, and each user to have a manager (the manager, who is also a user, may have a manager as well).

The app will require queries to know the maximum depth of a certain manager (so, in other words, the length of the longest path starting from a manager down to all people managed by that person). Additionally, it will need to be able to find users who are in the same group (a group can also be a member of another group).

To this point, the entire application had been modeled with JPA in a MySQL database. However, it is designed as an SOA, so changing the underlying data store of the service that handles users (user-service) wouldn't be all that expensive.

Are there any ways of doing this that don't require a graph database? If a graph database is necessary, should I store all user information in the graph, or just the appropriate relationships?

Upvotes: 0

Views: 402

Answers (1)

Michael Hunger
Michael Hunger

Reputation: 41676

If your basic model is

(group:Group)<-[:IN_GROUP]-(user:User)
(man:User)-[:MANAGES]->(sub:User)

you can do:

MATCH (manager:User {name:"Colin"})-[:MANAGES*]->(u:User)
RETURN u

for your second query

MATCH (manager:User {name:"Colin"})-[:MANAGES*]->(u:User)
      (u)-[:IN_GROUP]->(g)<-[:IN_GROUP]-(u2)
RETURN u.name as user, g.name as group, collect(u2.name) as colleagues

You can store all user information in the graph but you don't have to. Do what's easiest for your and best for your use-case.

Without a graph database you're up to write painful heavy-JOIN SQL queries, esp. for the variable length relationships.

Upvotes: 2

Related Questions