database - Datastore model design with ancestors -


i've used datastore 2 projects now, both projects failed utilize ancestor relationships. after lot of reading , researching, believe i've understood how design great datastore model.

imagine site similar reddit/instagram, users can create own categories (similar subreddits) other users can subscribe to. users can follow each other, , images uploaded different users uploaded these categories, displayed under specific user's profile (like in instagram). in mind, figured ideal design:

category - user - - image - subscriber user - follower - following 

with datastore model, believe should possible retrieve images uploaded 'user id' or 'category id', users subscribing 'category id', images uploaded 'category id'. users following or being followed 'user id', images uploaded users being followed 'user id'.

i appreciate feedback , potential ways improve datastore expert (i'm particuarly curious if there's wrong using 'user' ancestor in 2 different locations, it's child 'category' in 1 place not other)..


i hope make question more understandable/answerable :)

i have following entities:

category - id int64 - name string - etc..  user - username string (namekey) - password []byte - etc..  image - id int64 - storageid string - md5hash string - etc..  follow - id int64 - follower string - following string 

where category, user, image , follow entities , id, name, username, etc. property names.

so image entity descended user (who uploaded image) , category ancestors

the follow entity descended user ancestor

as subscriber i'm not sure if it's best make entirely new entity similar follow (in case potentially include date user first subscribed), or let become property

entity groups (all entities same root ancestor, including root ancestor) more consistency units when querying. 1 issue design scaling since entity groups limited sustained 1 transaction per second (you can burst higher).

with current design queries within single category consistent, you'd limited 1 new image per second.

since it's having consistent view of images in category isn't important ensuring can handle growth, might better have images descend root user entity (so user looking own images consistent) , have category id in property of image entity.

category - id int64 - name string - owneruserid string - etc..  user - username string (namekey) - password []byte - etc..  image (descends user) - id int64 - storageid string - md5hash string - categoryid int64 - etc.. 

now list images user 123 (strongly consistent):

select * image __key__ has ancestor (user, 123) 

list images user 123 in category 456 (strongly consistent):

select * image __key__ has ancestor (user, 123) , categoryid = 456 

list images in category 456 (eventually consistent):

select * image categoryid = 456 

list images (eventually consistent)

select * image 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -