Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 153 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

I read this question: I hit 50 days with 200+ rep two months ago; where's my ticket to the Epic club?

And one of the answers was

"The scheduled process that grants that badge has 1/10 chance to run every hour, so don't expect a deterministic schedule.

Just curios, why it's done like that?

share|improve this question
Too keep you guessing as to when you'll get the badge :) – psubsee2003 Jan 24 '14 at 17:26
Given how few people get it, it's probably because the expected value of the number of people getting it within the hour is less than 1/10. :P – Dennis Meng Jan 24 '14 at 17:27
To keep people guessing so everyone doesn't hammer the system at 00:00 UTC? – PearsonArtPhoto Jan 24 '14 at 17:43
Probably to conserve resources. Since it's a scheduled (batch) process, it presumably scans the database for new candidates, which can be time and processor consuming. Why couldn't you have just asked Sklivvz this question in a comment below his answer? – Robert Harvey Jan 24 '14 at 17:51
@RobertHarvey well, questions/answers are better than comments, as we're repeatedly told here. If anything I'd post question and link to it in a comment. – djechlin Jan 24 '14 at 18:11
@djechlin: Hm? That's a pretty broad-sweeping statement, using a premise that is almost certainly situation-specific. Comments are better than questions and answers when they are not questions or answers, or are merely asking for clarification. This particular question, while possibly interesting to someone, doesn't actually ask for input from the community, request support or ask for a feature. – Robert Harvey Jan 24 '14 at 18:16
@RobertHarvey that's true, we don't really have a category for "just curious" even though people often are curious. – djechlin Jan 24 '14 at 18:41
@RobertHarvey: I think you are right. I should have asked in the comments. However, standalone question has some benefits too. I will ask Sklivvz to take a look at this question. – Victor Ronin Jan 24 '14 at 20:12
up vote 9 down vote accepted

The reason we use a random distribution is to distribute the load evenly. If you think about the fact that random is, for all intents and purposes, uniformly distributed, then it becomes clear that over large numbers, this scheduling algorithm has to work.

Why don't we create an overall schedule, you might ask? The reason is that the constraints we have to work with would imply a lot of work for little or no gain:

  • There's much more than badges being executed on scheduled intervals
  • Almost every batch is executed once per site, or around 230 times currently
  • We keep on adding sites, so our schedule changes regularly.
  • The timing of the batches changes a lot as sites grow, and as we optimize them.
  • The batches basically all hit the same database server (a part from SO, which has its own), so load distribution is a real concern.

I can't really think of an algorithm which is much more efficient to deal with our constraints than shooting at random based on some "sane" probabilities.

The advantage of such a simple an algorithm should be evident: we haven't needed to change it in years and it served us well so far.

share|improve this answer
Don't forget all the free entertainment generated by it for folks waiting on the edge of their seats to see if a badge will suddenly appear... – Shog9 Jan 24 '14 at 21:14
Cool so now we have something new to tell when someone complains he didn't get a badge: it's randomness, blame the randomness. :-) – Shadow Wizard Jan 24 '14 at 21:25
Cached randomness. – Robert Harvey Jan 24 '14 at 23:22

Stack Exchange uses randomness to prevent batch processes from "colliding," much in the same way that collisions on an Ethernet bus are handled (each receiver backs off, and retransmits after a randomly-determined period of time).

Without that randomness, several batch processes might execute simultaneously, which would potentially bind up the servers.

Why not just schedule them? Because it's easier to just randomize them than it is to create a scheduling algorithm and assign each task a slot.

share|improve this answer
+1 for explanation, but -1 because I don't agree with saying "meh, let's just randomize it and we'll be good," so net 0 :P – Doorknob Jan 24 '14 at 18:55
@DoorknobofSnow: I didn't write the algorithm. :) – Robert Harvey Jan 24 '14 at 18:56
It's interesting explanation. However, scheduling + serial execution of batches sounds way better approach to eliminate collisions than randomization (at least per my understanding) – Victor Ronin Jan 24 '14 at 20:11
@VictorRonin: The only thing you're really trying to prevent is many batches running at the same time. Randomization won't eliminate the collisions entirely, but the probability of collisions decreases geometrically as a function of the number of potential collisions. – Robert Harvey Jan 24 '14 at 20:13

You must log in to answer this question.

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