I am trying to implement a page view system in my own website and I came up with some scenarios that led me to question why SO does it the way does.

Unless I am mistaken, I am under the assumption that SO has a "views" table that logs the postIp/userId or postId/IPAddress. There is also a viewCount column in the post table. I am aware that denormalizing this will allow faster reads when trying to read many questions. But it seems to me that the cost of denormalizing viewCount is very high. I must be wrong because people at SO know better than I do. But, assuming page views are stored as described above, you would do the following on every page request:

  1. Insert a new "view" record in the views table.
  2. Update the viewCount column in the original post.

That's one query to insert and one query to update. Is this more optimal than reading from a normalized relationship? Or am I reading too much into the data dump schema?


  • Scaling a web server is easy, scaling a dbase server is not. Normalized data requires joins on the query and that's expensive. SO is dbase heavy, the dbase server is the bottleneck. Nov 14, 2010 at 14:37
  • This is probably better suited to SO itself Nov 14, 2010 at 14:38
  • Why do you assume that page views are denormalized? If you're looking at SEDE, that's not the actual schema, it's just a reporting schema somebody designed around the CC dumps. I'm pretty sure that on the real site, views and are just cached, and refreshed once every few seconds. Actually I think the data for the entire front page is cached.
    – Aarobot
    Nov 14, 2010 at 15:49
  • @Aarobot Question views aren't cached. They're handled using a buffered write system.
    – Grace Note StaffMod
    Nov 14, 2010 at 16:04
  • @Grace: That's basically saying the same thing.
    – Aarobot
    Nov 14, 2010 at 17:40
  • @Grace Note, can you help me understand what a "buffered write scheme" means? I mean, how does it work? I tried searching but had no luck. It was all computer science jargon that I couldn't find comprehensible. Any links/explanations would be really helpful.
    – Mohamad
    Jul 11, 2011 at 19:36
  • @Mohamad I'd recommend you ask a question on our Programmers site on "What is a buffered write scheme?", explaining that you don't understand it. Don't ask for links, just ask what it is, and they should be able to provide you an easy-to-digest explanation.
    – Grace Note StaffMod
    Jul 11, 2011 at 19:54
  • @Grace Note, thanks for the info. I just asked a question here, before seeing this, but I guess I can reword my question, and the question here is a bit more specific. Thanks again!
    – Mohamad
    Jul 11, 2011 at 19:56

1 Answer 1


There is no views table. Only a counter that is incremented in a buffered write scheme.

  • does that mean you have a counter for every question? That's over 1 million counters :/
    – Mohamad
    Nov 14, 2010 at 21:07
  • 2
    @Mel: which would only be a problem if he was using, say, USER32 handles to represent the counters... Logging every request in the primary database would be vastly more costly.
    – Shog9
    Nov 15, 2010 at 18:46

You must log in to answer this question.

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