Should I expect stale results after redirect on local environment?
Asked Answered
L

1

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?

Lattonia answered 2/4, 2013 at 20:37 Comment(2)
Possible duplicate: https://mcmap.net/q/1623253/-gae-how-long-to-wait-for-eventual-consistency/8418Lessen
@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.Lattonia
B
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
Barbarity answered 2/4, 2013 at 22:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.