7

After I post a new entity to the datastore, I redirect the page to a new URL that lists all of the entities in that group. When I redirect, the page shows stale results and I have to reload to see the new list of entities in the datastore.

I know about eventual consistency. Is that why I'm seeing the stale result?

For example,

my datastore my have one user - User 1 Then, in a form, I add a user - User 2 This entity is put to the datastore and then I redirect to a new url, i.e. 'get/users'

On the redirect I only see User 1, but if I refresh the page I see User 2. Any way I can guarantee or help to prevent the stale results?

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
flynn
  • 1,572
  • 2
  • 12
  • 26
  • Possible duplicate: http://stackoverflow.com/q/15261099/8418 – Lipis Apr 02 '13 at 20:46
  • 1
    @Lipis, Not entirely - that has to do with specifically addressing consistency whereas this is asking if this IS in fact expected behavior AND related to consistency. – flynn Apr 02 '13 at 20:48

1 Answers1

7

Yes, this is caused by "eventual consistency" as you put it.

I have a few recommendations:

  1. Use AJAX. Using a redirect results in unnecessary extra work:
    • an extra (unnecessary) HTTP request (network bandwidth, latency, server resources, mobile data costs, etc.)
    • an extra (unnecessary) datastore query to confirm what you already know
  2. Use JavaScript to update the list of users displayed to the user on success of the XMLHttpRequest; don't perform another query.
  3. If you really need the user object, you can do a get by key (not a query) from the datastore and this will be strongly consistent.
  4. If you really want a strongly consistent query, use an ancestor query, which is strongly consistent. Send the results of that query back in the success response and update your UI accordingly.
    • Note: use of ancestor queries requires an entity group, which is limited to ~ 1 write/second; this rate would be sufficient for, say, recording comments on a blog post, but would likely be insufficient for creation of new users in your application
Fred Sauer
  • 1,012
  • 9
  • 20
bossylobster
  • 9,993
  • 1
  • 42
  • 61