Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommendations with hierarchical data on non-relational databases?

I'm developing an web application that uses a non-relational database as a backend (django-nonrel + AppEngine). I need to store some hierarchical data (projects/subproject_1/subproject_N/tasks), and I'm wondering which pattern should I use. For now I thought of:

  • Adjacency List (store the item's parent id)
  • Nested sets (store left and right values for the item)

In my case, the depth of nesting for a normal user will not exceed 4-5 levels. Also, on the UI, I would like to have a pagination for the items on the first level, to avoid to load too many items at the first page load.

From what I understand so far, nested sets are great when the hierarchy is used more for displaying. Adjacency lists are great when editing on the tree is done often. In my case I guess I need the displaying more than the editing (when using nested sets, even if the display would work great, the above pagination could complicate things on editing).

Do you have any thoughts and advice, based on your experience with the non-relational databases?

like image 944
Lucian Avatar asked Nov 15 '22 04:11

Lucian


1 Answers

How you store them depends on how you need to query them. For example, if you only need to find the direct children of a parent, an adjacency list model is probably simplest. If you want to enumerate entire subtrees, an ancestor list or nested sets work well - though I would avoid nested sets on App Engine.

If you need transactional integrity over all the objects in a tree - and won't be updating the tree as a whole more often than a few times a second - you should look into App Engine's support for entity groups and ancestors.

like image 54
Nick Johnson Avatar answered May 17 '23 10:05

Nick Johnson