6

Possible Duplicate:
How do badges get awarded? By a service or on change?

I'm impressed with the badge awarding service.

SO now has 770k users. Being able to serve badges for all of those users requires a smart solution. Badges are awarded every five minutes, and the system may not be able to scan every post by every user every five minutes.

I think the service works by by maintaining a list of active questions and their answers, since those are actually the only ones that need to be scanned. Inactive questions will not generate any badges. (Are there any exceptions to this?) That means we're talking about a global list variable to hold updated questions' IDs.

Is this actually how you guys at SE handling badge awarding?

5
  • 1
    Are you asking how the site knows which questions to examine to reward badges? If so, why on earth do you need to know? Aug 26, 2011 at 11:59
  • 2
    @lonesomeday I'm impressed with the professionalism used to handle such actions.
    – Ken D
    Aug 26, 2011 at 12:18
  • To start with, the badge check to bypass any user that has no new posts, or votes, or flags. Then given the use of SSD disks and lots of ram on the sqlserver, it is admiazing how fast some queries can go! Aug 26, 2011 at 13:22
  • @lan Ringrose, the information you gave needs citation, do you assure they do that?
    – Ken D
    Aug 26, 2011 at 13:42
  • Tumbleweed is one of the exceptions you ask about. It's all about INactivity.
    – Pops
    Dec 24, 2011 at 15:21

2 Answers 2

1

Each badge is different, and it's possible that stored procedures and/or triggers are used for some.

For instance, the "nice answer" which gets awarded to answers voted to 10 could be done in a number of ways.

One way would be to use a trigger on each answer upvote. If a new upvote occurs, see if the new total is 10 - if so, award a badge (assuming all the other badge requirements are met). This would allow real-time awarding, but would also be pretty expensive since there are several other checks to be made prior to awarding this badge.

Another would be to run a query every 5 minutes to gather all the answers that have been upvoted in the previous five minutes that were at 9 votes, and are now at 10 votes. This wouldn't require any triggers or stored procedures, and if run as a batch probably would be less overhead than the first option.

How stack exchange implements it is probably interesting, but its very specific to their database schema and site model. Any other implementation is going to be very different depending on the specifics of that implementation's database and model. If you want a better answer, ask the experts on stack overflow what they would do, given a site such as this. You'll have to word it carefully to avoid it being a question about stack exchange, and instead a question about how one might implement a badge process given a certain database schema (otherwise it'll get closed and/or moved here). You might receive surprising insight into how this is done elsewhere.

1
  • Also note that badges are awarded on different intervals, so there's really no single badge process.
    – Pollyanna
    Feb 22, 2012 at 15:59
-2

When there is a new badge, it is globaly scanned and badges are awarded for past posts. When system is going to check "old" badges, why would it check old inactive questions/answers? It checks only brand new and/or active posts.

5
  • That's what I said this is done by preserving a list of the newly active questions (and their answers) since actually only those need to be scanned, I'm sorry but did you add anything new to what I said?
    – Ken D
    Aug 26, 2011 at 11:51
  • @Lord I just agreed and said that thing you said is correct. Short answer would be "yes"
    – genesis
    Aug 26, 2011 at 11:58
  • 4
    why would it check old inactive questions/answers? It has to do this to ensure that badges are not given out incorrectly. For example, you have 3 answers with > 10 upvotes and 1 answer with 10 upvotes, which was downvoted to 9: You had 4 Nice Answer badges, but now only 3 posts qualify for the badge. If a new answer was posted and reached 10 upvotes, you should not receive a 5th Nice answer badge. Aug 26, 2011 at 12:00
  • @staticbeast But we could design it so that when a post score is changed, we re-add this post to the check list. i.e. we consider that post to be active again.
    – Ken D
    Aug 26, 2011 at 12:32
  • 1
    @staticbeast: Did you notice inactive? by inactive I mean no votes, no edits
    – genesis
    Aug 26, 2011 at 12:33

Not the answer you're looking for? Browse other questions tagged .