2

Normalization not in a general relational database sense, in this context.

I have received reports from a User. The data in these reports was generated roughly at the same time, making the timestamp the same for all reports gathered in one request.

I'm still pretty new to datastore, and I know you can query on properties, you have to grab the ancestors' entity's key to traverse down... so I'm wondering which one is better performance and "write/read/etc" wise.

Should I do:

Option 1:

  • User (Entity, ancestor of ReportBundle): general user information properties
  • ReportBundle (Entity, ancestor of Report): timestamp
  • Report (Entity): general data properties

Option 2:

  • User (Entity, ancestor of Report): insert general user information properties
  • Report (Entity): timestamp property AND general data properties
2
  • to get a idea which solutions could be best from performance point of view, you should describe how you would like to read write the date, how to read, and how often to write / read which kind of entity, but as hint, getting by id is always the fastest Jun 13, 2013 at 12:28
  • 1
    My non-answer is this: Don't worry about this! Write a few functions that query and save to the datastore using them. If you decide you want to change your properties or the way you query them later, do it then. Don't worry about this "problem" until it's actually a problem. I guarantee there are more interesting and important things you could be spending your time on; skip this for now. Do whichever is more convenient to do correctly right now, and get on with life.
    – Ezra
    Jun 16, 2013 at 16:43

2 Answers 2

3
+100

Do option 2:

Because, you save time for reading and writing an additional Entity. You also save database operations (which in the end will save money).

As I see from your options, you need to check the timestamp property anyhow so putting it inside the report object would be fine,
also your code is less complex and better maintainable.

As mentioned from Chris and in comments, using datastore means thinking denormalized.

It's better to store the data twice then doing complex queries, goal for your data design should be to get the entities by ID.

Doing so will also save on the amount of indexes you may need. This is important to know.

The reason why the amount of indexes is limited, is because of denormalization.
For each index you create, datastore creates a new table in behind, which holds the data in the right order based on your index. So when you use indexes your data is already stored more then one time. The good thing about this behavior is that writes are faster, because you can write to all the index tables in parallel. Also reads, because you read data already in right order based on your index.

Knowing this, and if only these 2 options are available, option 2 would be the better one.

3

We have lots of very denormalized models because of the inability to do JOINs. You should think about how you are going to process the data, if you might expect request timeouts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.