0

I couldn't understand the difference between Embedded Entity and Entity using ancestor path on GCP Datastore.

I could understand following things.

  • By using ancestor path, it can manage entities as different kind, but there's writing 1 times/sec limit.
  • Ancestor path makes Strong Consistency

But these things are same as using embedded entity.

So I'm confusing how to use embedded entity and ancestor path appropriately.


Now I'm developing a model for form like Google Form.

It can be added items freely, so I'm thinking using embedded entity named Item or create kind named Item and use Ancestor path for Form class.

1 Answers1

3

The embedded "entity" is not a real entity, it's just a property inside the "container" entity in which it is embedded. From Embedded entities (emphasis mine):

You may sometimes find it convenient to embed one entity as a property of another entity.

You still have the 1 write/sec limit for that "container" entity. And you cannot update just the embedded "entity", you have to update the entire "container" entity.

The embedded entity may appear strongly consistent, but only in the sense that it's consistent with the other data in the "container" entity (nothing special here, the same is true for any property inside an entity). It is still eventually consistent when it comes to making queries using its values. And you cannot make such queries inside transactions.

Entities tied by ancestry on the other hand are real, distinct entities, all being placed inside the same entity group. The entire entity group is subject to the 1 write/sec limit. Ancestor queries have a scope limited to the respective entity group, are strongly consistent can be done inside transactions.

If strong consistency is what you're after then you have to use the datastore ancestry to tie the respective entities together.

Otherwise you can use either the embedded entities or simply plain entities of a different kind and establish the relationships between entities using Key properties. See also E-commerce Product Categories in Google App Engine (Python)

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97