Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

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?

share|improve this question

marked as duplicate by Adam Lear Feb 23 '12 at 5:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Are you asking how the site knows which questions to examine to reward badges? If so, why on earth do you need to know? – lonesomeday Aug 26 '11 at 11:59
@lonesomeday I'm impressed with the professionalism used to handle such actions. – Kenan Deen Aug 26 '11 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! – Ian Ringrose Aug 26 '11 at 13:22
@lan Ringrose, the information you gave needs citation, do you assure they do that? – Kenan Deen Aug 26 '11 at 13:42
Tumbleweed is one of the exceptions you ask about. It's all about INactivity. – Pops Dec 24 '11 at 15:21

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.

share|improve this answer
Also note that badges are awarded on different intervals, so there's really no single badge process. – Adam Davis Feb 22 '12 at 15:59

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.

share|improve this answer
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? – Kenan Deen Aug 26 '11 at 11:51
@Lord I just agreed and said that thing you said is correct. Short answer would be "yes" – genesis Aug 26 '11 at 11:58
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. – staticbeast Aug 26 '11 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. – Kenan Deen Aug 26 '11 at 12:32
@staticbeast: Did you notice inactive? by inactive I mean no votes, no edits – genesis Aug 26 '11 at 12:33

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