0

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

MobileMon
  • 8,341
  • 5
  • 56
  • 75

2 Answers2

1

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.

someone1
  • 3,570
  • 2
  • 22
  • 35
  • So it would be safe to say the way I suggested WITHOUT entity groups is ok?? – MobileMon Apr 11 '13 at 21:04
  • Yes but you don't need to explicitly make id fields, you can use the key associated with every entity – someone1 Apr 12 '13 at 22:07
  • yes I can use the ID fields but in order to link a comment to a post, I'll still need to explicitly declare a postId field in the comment entity (which is the key associated with the post entity). Do you concur? – MobileMon Apr 16 '13 at 13:06
  • What I mean to say is that every entity in datastore is automatically assigned a Key. I think this is different in python than it is in JAVA, and depends on how JDO vs JPA, etc.. This link shows how to model using JDO, where you give an object a key field but it looks like it will automatically be generated. https://developers.google.com/appengine/docs/java/datastore/jdo/relationships – someone1 Apr 16 '13 at 13:23
0

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

  • repeated properties are ok if you know you will have to be relatively small (bounded in size) sets. Remember an entity is limited in size to 1Mb. So these tend not to scale. Entity groups do make it easy to query for all children using ancestor queries. However if you have large numbers of concurrent writes within an entity group, then you will an increased likelyhood of write conflicts. So these are all factors that influence the design – Tim Hoffman Apr 11 '13 at 13:47
  • I guess I should delete my answer? –  Apr 11 '13 at 13:58
  • 1
    its still relevant, OP needs to understand the different approaches. He was using facebook as an example ;-) – Tim Hoffman Apr 11 '13 at 14:26
  • From my research I do not think this is a good answer. Entity groups seem to be critical to maintaining consistency as well as reducing costs from accessing the data. – Adam S. Jul 30 '14 at 23:05