Reputation: 8661
General question on how to model a Google App Engine datastore. I'm confused about the entity groups part. Lets take for instance a Facebook example where there are 3 entities: Users, Posts, and Comments.
Right now how I would implement it is just like a traditional RDBMS. Each Post has a userId property and each Comment has a postId property and userId property that I would link back to each other through queries. I DO NOT USE ANY ENTITY GROUPS. BUT, I feel like this would be a good place for entity groups since Posts cannot live without Users and Comments cannot live without Posts. Would I set this up in a way that Posts are children of Users? And Comments are children of Posts and Users??
Once again, just to be clear, I'm confused about when to use entity groups.
**Update: I'm using Java
Upvotes: 0
Views: 676
Reputation: 3570
You should know that entity groups have a soft limit of 1 write/second on the High Replication Datastore. Keep this in mind when creating your modeling choices
A good reason to use entity groups would be for consistent queries or updating multiple models transactionally. If you need to update 1 or more models using a transaction, they must belong to the same entity group (although there are now cross group transactions which support up to 5 different groups at a time). If you want to perform a strongly consistent query (not eventually consistent query as is by default), you need to specify a parent in the query. Read more about strong consistency here
You can read about entity group usage here
You can model out relations as you described, but you can also use ndb.KeyProperty
or db.ReferenceProperty
to reference from one model to another.
Update for JAVA
What I said above for entity groups stands true for JAVA as well as python, except you would use com.google.appengine.api.datastore.Key
to reference objects between Models.
Again, for both JAVA/Python, I believe all entities within a single entity group can be retrived faster since the data is kept on a single node (this was true with the M/S datastore, not sure about HRD). From here:
Entity group relationships tell App Engine to store several entities in the same part of the distributed network.
Upvotes: 1
Reputation:
I gather you are using python? If you use NDB, which you should use, you can store your "foreign id's" or keys as a key property list
message = ndb.KeyProperty(kind=Message, repeated=True)
But read up on the options as there are many ;)
https://developers.google.com/appengine/docs/python/ndb/properties
Upvotes: 0