Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do sites like stackoverflow with badges use some type of delayed job to determine when to award a new badge?

Stackoverflow has a nifty badge system. One thing I noticed is that badges are not immediately awarded, but sometimes seem to have some type of a delay after I meet the criteria. I've noticed this on some other sites that have badges as well.

Presumably this is because they are using a delayed job that scans periodically to see if any new badges need to be awarded. I see this approach also advised here:
How to implement badges?

However, I don't really see why this should be necessary, and am favoring in my implementation to simply have a system where after a relevant action is performed, for example a new comment is posted, a checkAwardBadge function is called, which checks if the user meets the criteria for a new comment badge.

Speedwise, I was thinking that all relevant user stats would simply be stashed in a submodel of User, like UserStats so that instead of having to count the number of comments each time, it would just be a simple query.

It strikes me that the system I'm favoring should be fast and very simple to understand. Are there downsides I'm missing here on why it's necessary to complicate things with delayed jobs?

To clarify: I plan to have an abstract class Achievements, with each actual Achievement an implementation of Achievements. Each Achievement will have a checkAwardBadge function, which can be called from the controller, or even a delayed job if I should choose to go that route, or any time really, to check whether a user has earned a certain badge. Thus, achievement code would all be centralized.

like image 831
William Jones Avatar asked Jul 29 '10 19:07

William Jones


People also ask

What is badges in stackoverflow?

Badges are little bits of digital flair that you earn for almost every kind of activity. The number and type of badges you've earned are displayed together with your name and reputation score around your team as part of your user card. The badge system exists for two reasons...

What is the name of the badge given when you answer one question in stackoverflow?

To this day we have awarded over 66 million badges to more than 8.6 million users. The most common badge is the “popular question,” which has been given out over five million times, and is awarded to users who ask a question that is viewed 1000 times.

What is gold badge in stackoverflow?

Silver badges are more uncommon than bronze badges, but attainable if you're dedicated. Gold badges. Gold badges are for the most committed users. They reward the most difficult feats; you'll have to not only participate in the community but be skilled, knowledgeable, and dedicated to earn these.


1 Answers

Your implementation may work on simple scenarios (like the one you are describing), but if things gets more complex you have a solution that:

  1. Makes unnecessary checks in every action
  2. Adds penalty performance to every action
  3. Does not scale
  4. Does not have a central place for all the rules.
like image 109
Eduardo Molteni Avatar answered Sep 28 '22 07:09

Eduardo Molteni