Question: I have been playing around with google app engine and its datastore recently and created a datamodel and relationships using reference properties. 

However I am unclear about the concept of ancestors wrt the datastore. What is their purpose and why should I use them? How do they relate to reference properties of datastore entities?

Answer: 
The example usually used is an author and their books. 

Each book is stored in the datastore as a separate entity, with it's name and it's author stored as fields in the model. 

If you want to know all books by a single author, you can run a query such that

```
book.author == desired_author

```

But with ancestors you can also save each book and set a model (a new author model) to be it's parent (it's ancestor). 

So now you can simply say "show me all books that have this author as parent". 

Or rather "show me all children of this ancestor" and all books by that author are returned. 

It might not seem that useful in this example, but if you imagine instead of "author" you have "user" and instead of "book" you have "message board message" and tens of thousands of messages and suddenly it becomes very handy to be able to find all messages by user (e.g. show me my own messages). 

<https://developers.google.com/appengine/docs/python/datastore/queryclass#Query_ancestor>

```
ancestor (ancestor)
Adds an ancestor filter to the query. The query will return only entities with the specified ancestor.

```

There are also benefits in costs for finding each record I expect.
Providing an ancestor makes your (new) entity part of the same entitygroup as the ancestor provided. Hence all entities with a common root entity as an ancestor get stored in the same datastore node, this 'locality' permits numerous actions to be performed on all these entities (in the same entitygroup) all within a transaction. Then to any query which contains an ancestor query (such as only return entities which are children the common root entity) , these actions will appear to occur simultaniously (atomically) or not at all.

Ref:
<http://www2.mta.ac.il/~kirsh/download/MTA%20NoSQL%20Seminar/Lectures/GAE.pdf>