Snowman
Snowman

Reputation: 32061

Structuring Google App Engine for strong consistency

I want to run over this plan I have for achieving strong consistency with my GAE structure. Currently, here's what I have (it's really simple, I promise):

You have a Class (Class meaning Classroom not a programming "class") model and an Assignment model and also a User model. Now, a Class has an integer list property called memberIds, which is an indexed list of User ids. A class also has a string list of Assignment ids.

Anytime a new Assignment is created, its respective Class entity is also updated and adds the new Assignment id to its list.

What I want to do is get new Assignments for a user. What I do is query for all Classes where memberId = currentUserId. Each Class I get back has a list of assignment ids. I use those ids to get their respective Assignments by key. After months with this data model, I just realized that I might not get strong consistency with this (for the Class query part).

If user A posts an assignment (which consequently updates ClassA), user B who checks in for new assignments a fraction of a second later might not yet see the updated changes to ClassA (right?).

This is undesired. One solution would be to user ancestor queries, but that is not possible in my case, and entity groups are limited to 1 write per second, and I'm not sure if that's enough for my case.

So here's what I figured: anytime a new assignment is posted, we do this:

So throughout this process, I've never queried. All results should be strongly consistent, right? Is this a good solution? Am I overcomplicating things? Are my read/write costs skyrocketing with this? What do you think?

Upvotes: 1

Views: 563

Answers (2)

Binu Jasim
Binu Jasim

Reputation: 355

I think using ancestor queries is a better solution.

  • Set the ancestor of the Assignment entities as the Class to which the assignment is allotted
  • Set the ancestor of a Student entity as the Class to which the student belongs.

This way all the assignments and students in a particular class belong to the same entity group. So Strong consistency is guaranteed w.r.t a query that has to deal with only a single class.

N.B. I am assuming that not too many people won't be posting assignments into a class at the same time. (but any number of people can post assignments into different classes, as they belong to different entity groups)

Upvotes: 0

Peter Knego
Peter Knego

Reputation: 80330

Queries are not strongly consistent. Gets are strongly consistent.

I think you did the right thing:

  1. Your access is strongly consistent.
  2. Your reads will be cheaper: one get is half cheaper as then query that returns one entity.
  3. You writes will be more expensive: you also need to update all User entities.

So the cost depends on your usage pattern: how many assignment reads do you have vs new assignment creation.

Upvotes: 2

Related Questions