This Stack Overflow question at the time I looked at it, had comments from 3 different users, 2 close votes - and a view count of 1:

enter image description here

Obviously the view count shown is out of date. A minor issue, but I thought it worth reporting, as I haven't found any prior similar posts.


1 Answer 1


This isn't actually related to the proposed duplicate, it's a separate (recent) caching mechanism. Starting a few weeks ago, we cache the view count for 5 minutes at a time (this may vary later, but it's the same on SO as other sites, for now).

View Count is an incredibly expensive thing for SO in particular given it's traffic numbers, we have to keep several things in mind, it has to be:

  • synced across all web servers hosting SO (6 right now)
  • written to the database
    • indexed, meaning that update isn't free or very cheap overall
    • written often, but not insanely often, like every view

To do this in a reasonable way, a few things happen here that cache at different levels:

  1. To keep things sane, we rack up some view counts before updating them in a batch
  2. The batch is per web server in local cache, then when it fills, views are incremented in the database
  3. After 5 minutes, the cache shared between servers expires and refreshes from the database

Now immediately you think "well that's way more than 5 minutes"...that's not the case for SO. That per-server buffer isn't that large (300 at the moment for SO, 30 for other sites), it flushes in under a minute...much faster at peak traffic times.

All this means the effective delay in view count is about 5 minutes - that's why you'll see some strange numbers on a brand new question.

In the example above, given the time in the screenshot, a refresh over the next minute should update the view count (now at 50), since the question was asked at off-peak hours and that's the maximum time for that per-server buffer to do it's work.

  • 1
    +1 for the technical background info. Just as a thought experiment in the quest for perfection: since out of date view counts are most noticeable with new posts, would it make sense to refresh the view counts on new posts (e.g. younger than 5-10 mins) more often (maybe by using a separate cache for these)? I am not a web expert, so feel free to point out if there is any obvious problem with this :-) Feb 25, 2011 at 14:19
  • @Péter - That's not a bad idea at all, starting in the build going out tonight, new questions less than 10 minutes old will cache for 30 seconds instead of 5 min, once they're 10 min old, they'll cache for 5 minutes like all other questions. Feb 25, 2011 at 14:41
  • @Nick: If you flush the buffer to the database every 5 minutes, how do you enforce the rule of "1 request per IP per 15 minutes counts as a view"? I mean after you've cleared the buffer after 5 minutes you don't have the raw request data any longer.
    – user136634
    Apr 18, 2011 at 19:59
  • @Developer - that's a different, independent throttling mechanism :) Apr 18, 2011 at 20:07
  • Nick, could you please share some more details? I'm trying to implement something similar and I could really use some input.
    – user136634
    Apr 18, 2011 at 20:17
  • @Developer - you can use a simple expiring cache object that ties a user to the question, if it exists, don't increment Apr 18, 2011 at 20:39
  • @Nick, that's an interesting idea, thank you. And that cache object expires at predetermined points like every :15, :30, :45 and :00 minutes?
    – user136634
    Apr 18, 2011 at 20:50
  • @Developer - XX min from current for example Apr 18, 2011 at 20:51
  • Btw, that counter url found in each page with some random value which is changed every 15-18 minutes, does it have something to do with this "throttling mechanism"? I've recently asked a question about it, can't have missed it: meta.stackexchange.com/questions/87092/…
    – user136634
    Apr 18, 2011 at 20:52
  • So I've tried this approach and it seems to be working fine. Thank you for your useful hint.
    – user136634
    Apr 20, 2011 at 19:36

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