Ancestor relation in datastore

前端 未结 2 439
清酒与你
清酒与你 2020-12-06 22:11

I have three entities: user, post and comment. A user may have multiple posts and a post may ha

相关标签:
2条回答
  • 2020-12-06 22:22

    I think the question to ask is: Are you expecting:

    • User to create Posts more than once per seconds (I doubt :)
    • People to comment on a Post more than once per second (could happen)

    It not, then having ancestors queries will be faster than normal queries. So it depends of your usecase. I'd go for query speed unless you know you will have thousands of comments on posts.

    0 讨论(0)
  • 2020-12-06 22:31

    Yes, you are correct: all ancestry-related entities are in the same entity group, which raises 2 scalability issues: data contention and maximum entity group write rate of 1/s. See somehow related Is there an Entity Group Max Size?

    There are advantages of using ancestries and some may be willing to sacrifice scalability for them (see What would be the purpose of putting all datastore entities in a single group?), but IMHO not for your kind of app: I think you'll agree that it's not really critical to see every new user/post/comment in random searches immediately after it is created (i.e. strong consistency) - the fact that it eventually appears is IMHO good enough.

    Simply having no ancestry at all and adding additional model properties (entity keys or even just entity key IDs for entities which never have ancestors) to allow cross-referencing entities is the more scalable approach and IMHO fits well with your app.

    0 讨论(0)
提交回复
热议问题