Search code examples
database-designmongodbneo4jachievementsbadge

how to architect achievements and badging with nosql


I currently have an social game app using mongodb for it's database. My question is what are some suggestions if I want to create a points and badging system. The business logic for achievements/badges could become quite complicated and are very ad-hoc so doing real-time awarding of badges would not seem efficient. I am imagining adding tracked actions to a queue somewhere, i.e. Amazon SQS, or just using a user's activity feed as a queue, and have another offline worker process going through and just processing the effects of every action/activity to see if the threshold for any particular badge is crossed.

My worry with this method is that it seems like the badge queries can become quite intensive and I'd also have to track a very large number of actions. I can envision achievements ranging from things like a badge for someone that's scored 2nd place every week for the past 4 weeks, or a badge for someone that has a friend in every single one of 50 states... etc...

Are there more elegant or tried-and-true methods for this type of stuff? Would it make sense to use another database for achievements/activity feed/leaderboards besides mongo, creating a mongo/other db hybrid environment?

Are choices like Redis, Neo4J, or just plain old SQL Server a good choice for a hybrid solution? I like Mongo so that will stay as our primary db, but curious to see if adding another db to the mix would help.


Solution

  • This is a good candidate for running map reduce on the database. you can run them on a less regular basis, using them for offline computation of the data that you want.

    http://www.mongodb.org/display/DOCS/MapReduce

    You could use other tools to do this, but in your summary i cannot see any compelling reason to add complexity at this stage. I would explore map reduce, try it out and then if it does not meet your needs, expand your options. but at that time, you would at least have identified concrete bottlenecks, if any.