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 was surprised by the system that awards badges whenever a certain task is completed. How is that implemented? Does it use triggers in the database? Is it done purely in code? If it is code, what is the design?

I realize that maybe no-one knows the exact answer, but how do you think it's implemented?

share|improve this question

marked as duplicate by Lance Roberts, Pops, mmyers Oct 11 '11 at 17:11

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.

5  
BD = BetaDase?? – JNK Oct 10 '11 at 20:43
6  
Sorry I am Spanish (Base de Datos) LOL – eversor Oct 10 '11 at 20:48
3  

From what I've understood, at least some are implemented as timed jobs that periodically check if a new badge should be awarded. I assume these run on different intervals depending on the badge.

I don't know if some of the more trivial badges are awarded based on a trigger, or if the job just runs really frequently for those. They appear to be awarded quite quickly.

share|improve this answer
    
But don't you think thats a huge use of resources, i mean, if for each badge you have to check a great amount of users... – eversor Oct 10 '11 at 20:56
1  
@eversor: For those that can be hooked to triggers, not really, especially if indices are set up intelligently. Some of the others are only scanned for occasionally (once a day?) so they could be quite expensive I suppose. – Donal Fellows Oct 10 '11 at 22:16

Only the developers can answer this 100% which I doubt they will, as programmers prefer to keep the code/logic behind hidden.

From what I've seen, all the "first time you [action here]" badges are awarded instantly - no timed job in this case. So this means code running in every relevant place checking if it's your first [something here] it will add a badge.

More complex badges like Revival (Answered more than 30 days later as first answer scoring 2 or more) already requires checking more conditions, so most lilkely it's done by some timed job probably every few hours.

share|improve this answer
3  
"I doubt they will, as programmers prefer to keep the code/logic behind hidden" -- I think SO is a bit different; multiple times I've seen devs post actual code snippets when explaining how something works/what was wrong – Michael Mrozek Oct 11 '11 at 11:37
    
@MichaelMrozek true, hope this will be the case on this matter too. :) – Shadow Wizard Oct 11 '11 at 11:41

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