2

Say you have the hierarchical storage concept of "Foo." "Foo" holds an id, various values, and zero to many "Foo." Obviously, in turn, the child elements can hold zero to many Foos. The data is purely hierarchical: a given Foo will belong to zero to one Foos, and thus there is never a concern of multiple parents.

The data is stored in some sort of data format (JSON, BSON, XML, etc), within a storage technology (such as MongoDB, flat file, etc). We'll assume that both of these are unknown, so a system agnostic architecture is desired.

What architecture principles/choices would dictate if the objects should be stored hierarchical (directly into the storage medium with children existing as actual children) or flatly, with all parents and children at the same level (and references to children via ids).


My inclination is that storing the objects in the natural hierarchical pattern is the ideal, however I'm uncertain if this is possibly a performance concern (if a specific child is needed to be found, which would require some sort of searching through the tree structure?).

I've seen Web APIs exposed both ways, and code repositories dealing with both forms. I can't, however, find the decision points/architecture concerns formally dealt with.

gnat
20.5k29 gold badges117 silver badges308 bronze badges
asked May 23, 2016 at 16:30

1 Answer 1

4

I think two issues to consider are:

  1. (and you're referenced this above) - do you need to find child nodes ? In which case you perhaps want to avoid storing sizeable hierarchies and instead store the individual Foos such that they're immediately searchable. That may impact tree construction/retrieval times
  2. Do you want to move children between trees? If you do, again, I would look to keep these separate otherwise you'll have to search for these and then detach and reassign to a new tree

I think the APIs for clients reflect what the clients want to do, rather than the underlying storage mechanism. Understanding what the clients want (as per the above, do they want to search, rebuild etc.) will inform your decision further.

I note also that you're completely undecided on the underlying storage mechanism. A document-oriented database will have very different characteristics from a flat-file solution. As such you should consider the client-facing API separately from the underlying technology and let the client requirements inform your non-functional requirements.

answered May 23, 2016 at 17:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.