Ancestors are hierarchical - they can be used when you have hierarchical relationships between things (for instance, in a forum system you might have Forum
s which have Topic
s which in turn have Post
s).
KeyProperty
is not inherently hierarchical - it just provides a link. It should be used for non-hierarchical linkages between items. Reusing the forum example from the previous paragraph, one might use a KeyProperty
to link a Post
to the User
who created it - because User
s aren't in the forum-topic-post hierarchy. They're related to all 3 (for instance, a User
might create a post, create a topic, and/or moderate a forum).
In the end, however, the main tradeoff between ancestors and keys is in consistency vs. throughput: ancestor-based queries give you strong consistency relative to recent updates, but impose a limit of 1 modification per second for any given entity group and a maximum size limit for the group due to lack of distribution.