How many users and how many games?

--
Colin
+1 320 221 9531



On Jan 22, 2014, at 10:59 AM, Kasper Middelboe Petersen <
kas...@sybogames.com> wrote:

I can think of two cases where something bad would happen in this case:
1. Something bad happens after the increment but before some or all of the
update friend list is finished
2. Someone spams two scores at the same time creating a race condition
where one of them could have a score that is not yet updated (or the old
score, depending on if the increment of the highscore is done before or
after the friend updates)

Both are unlikely things to have happen often, but I'm going to have quite
a few users using the system and it would be bound to happen and I would
really like to avoid having data corruption (especially of the kind that is
also obvious to the users) if it can at all be avoided.

Also should it happen there is no way to neither detect nor clean it up.


On Wed, Jan 22, 2014 at 6:48 PM, Colin <colpcl...@gmail.com> wrote:

> Read users score, increment, update friends list, update user with new
> high score
>
> Would that work?
>
> --
> Colin
> +1 320 221 9531
>
>
>
> > On Jan 22, 2014, at 11:44 AM, Kasper Middelboe Petersen <
> kas...@sybogames.com> wrote:
> >
> > Hi!
> >
> > I'm a little worried about the data model I have come up with for
> handling highscores.
> >
> > I have a lot of users. Each user has a number of friends. I need a
> highscore list pr friend list.
> >
> > I would like to have it optimized for reading the highscores as opposed
> to setting a new highscore as the use case would suggest I would need to
> read the list a lot more than I would need write new highscores.
> >
> > Currently I have the following tables:
> > CREATE TABLE user (userId uuid, name varchar, highscore int, bestcombo
> int, PRIMARY KEY(userId))
> > CREATE TABLE highscore (userId uuid, score int, name varchar, PRIMARY
> KEY(userId, score, name)) WITH CLUSTERING ORDER BY (score DESC);
> > ... and a tables for friends - for the purpose of this mail assume
> everyone is friends with everyone else
> >
> > Reading the highscore list for a given user is easy. SELECT * FROM
> highscores WHERE userId = <id>.
> >
> > Problem is setting a new highscore.
> > 1. I need to read-before-write to get the old score
> > 2. I'm screwed if something goes wrong and the old score gets
> overwritten before all the friends highscore lists gets updated - and it is
> an highly visible error due to the same user is on the highscore multiple
> times.
> >
> > I would very much appreciate some feedback and/or alternatives to how to
> solve this with Cassandra.
> >
> >
> > Thanks,
> > Kasper
>

Reply via email to