I'm writing a game backend in app engine where progress in each game
is described by timestamped events. So any time a player takes a turn
or types a chat message it generates one or more events, each
timestamped using datetime.utcnow(). Each game and its data form an
entity group in the datastore, and each user can have multiple games
in progress at any given time. On the client side the game keeps
track of the timestamp of the last event it's seen (across *all* the
user's games) and periodically requests all newer events.
But of course GAE is a distributed system and utcnow() is not going to
be consistent across different nodes of the system, so this won't
work. Eventually there will be two near-simultaneous events in
different games that get written to the datastore in the "wrong" order
and one of them will never be seen because it's "older" than the
"newest" event.
So what's the right way to solve this kind of problem? I like the
concept of a global event stream for each user, but maybe I have to
abandon that model and use one event stream per game. Or maybe it
would be better to assume that the clocks won't be *too* far off and
request events with timestamps greater than N seconds before the last
event the client's seen. I'd be grateful for any recommendations or
suggestions.
Thanks,
-n8
Hi Nick,
Wow, that's impressive! That's a very useful bit of information. Are
memcache writes guaranteed ordered wrt datastore writes as well, or is
it possible for another part of the system to see them in different
orders?
Cheers,
-n8
On Jul 22, 9:56 am, "Nick Johnson (Google)" <nick.john...@google.com>
wrote:
> Hi n8gray,
>
> The Datastore is strongly consistent. As such, all processes will see
> changes happen in the same order, even across entity groups - and at
> any one point in time, all processes will have a consistent view of
> the datastore.