Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Achievements / Badges system

I have been browsing this site for the answer but I'm still a little unsure how to plan a similar system in its database structure and implementation.

In PHP and MySQL it would be clear that some achievements are earned immediately (when a specialized action is taken, in SO case: Filled out all profile fields), although I know SO updates and assigns badges after a certain amount of time. With so many users & badges wouldn't this create performance problems (in terms of scale: high number of both users & badges).

So the database structure I assume would something as simple as:

Badges     |    Badges_User      |    User ---------------------------------------------- bd_id      |    bd_id            |  user_id bd_name    |    user_id          |  etc bd_desc    |    assigned(bool)   |              |    assigned_at      | 

But as some people have said it would be better to have an incremental style approach so a user who has 1,000,000 forum posts wont slow any function down.

Would it then be another table for badges that could be incremental or just a 'progress' field in the badges_user table above?

Thanks for reading and please focus on the scalability of the desired system (like SO thousands of users and 20 to 40 badges).

EDIT: to some iron out some confusion I had assigned_at as a Date/Time, the criteria for awarding the badge would be best placed inside prepared queries/functions for each badge wouldn't it? (better flexibility)

like image 961
bluedaniel Avatar asked Nov 16 '09 20:11

bluedaniel


People also ask

What are achievement badges?

Achievement badges are awarded to you when you reach certain milestones in the game. Before the 0.41. 2 Android and 1.11. 2 iOS update, the badges were only used to track your stats, so you could easily see how you were doing and brag to your friends.

What is badge pathway?

Badge pathways are an evolving concept that can be defined as digital solutions that enable individuals to use digital badges to move towards a goal or opportunity, or that can be used as an 'infographic' to document an individual's pathway towards a certain goal, with badges.

Is badge a reward?

Badges are a common feature of many different types of application, including game apps and learning apps. They sometimes go by different names, but the principle is the same – you get a badge or similar reward for completing various tasks.

Why do achievements/trophies and badges work?

Eight potential reasons why badges, achievements, and trophies might work are: They anchor our performance expectations higher. Having goals increases our self efficacy. Completing goals leads to satisfaction.


1 Answers

I think the structure you've suggested (without the "assigned" field as per the comments) would work, with the addition of an additional table, say "Submissions_User", containing a reference to user_id & an incrementing field for counting submissions. Then all you'd need is an "event listener" as per this post and methinks you'd be set.

EDIT: For the achievement badges, run the event listener upon each submission (only for the user making the submission of course), and award any relevant badge on the spot. For the time-based badges, I would run a CRON job each night. Loop through the complete user list once and award badges as applicable.

like image 64
da5id Avatar answered Oct 02 '22 13:10

da5id