pbount
pbount

Reputation: 1803

How do multiple relationships for a single node affect performance of a neo4j database

I have a database which will store a number of users and the items belonging to those users. users and items will be stored as nodes. My initial approach was to have a user node with properties of username, email, and item with properties name and category, with their inbetween relatiohsip being:

(item)-[BELONGS_TO]->(user)

After reading an article in the neo4j blog, I moved the category property into a separate node, as it may belong to multiple items.

enter image description here

What I am concerned about is that now in a scenario of thousands of items, category nodes would have thousands of relationships. How would that affect the overall performance if I were to search for a single item and the categories it belongs to?

Upvotes: 0

Views: 341

Answers (2)

Tom Geudens
Tom Geudens

Reputation: 2666

Dense nodes are indeed an issue (and there's quite a few approaches to increase the performance / solve the issue). Having said that, the denseness here is on the side of the category (1 category having thousands of relationships with items). If your entry point into the graph is the item however ... getting all the categories it belongs to (just a few I imagine) should not cause any problems whatsoever.

Hope this helps, Tom

Upvotes: 1

cybersam
cybersam

Reputation: 67019

You can avoid having to create Category nodes and the relationships to them by indexing the category property of Item nodes. This would allow you to quickly find all the Items that belong to a single category.

Upvotes: 1

Related Questions