Say I have folders, documents, and comments. Understanding that we don't want nested data, there seem to be a few choices on how to store hierarchical data:
A. Encoding just the last 2 steps of the logical path in the ref:
/users/$user_key
/folders/$folder_key
/folder_documents/$folder_key/$document_key
/document_comments/$document_key/$comment_key
/comment_likes/$comment_key/$user_key
B. Encoding the full logical path in the ref, but adding path components so that client can efficiently fetch only what it needs:
/users/$user_key
/folders/info/$folder_key
/folders/documents/$folder_key/info/$document_key
/folders/documents/$folder_key/comments/$document_key/info/$comment_key
/folders/documents/$folder_key/comments/$document_key/likes/$comment_key/info/$user_key
C. Encoding no path information in ref, and adding indices to fetch subsets of data such as all the comments for a document.
/users/$user_key
/folders/$folder_key
/documents/$document_key
/comments/$comment_key
/likes/$comment_key/$user_key (still want 2 levels here, probably)
Are there others I haven’t considered?
I am currently doing A because that's what's suggested in that link above… But I don’t like it too much because it requires knowing the parent key in order to fetch an object. Usually on the client I know this anyway, but things get messier when adding a server component to handle side-effects like notifications. For example, if someone likes a comment and we want to send a notification, the server needs to know the document key to fetch the comment text that was liked. The work-arounds seem to be replicating data or passing parent keys around.
I think B might work pretty well, but it feels a little baroque.
I recently thought of C, and wonder what the performance implications are.