What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 131 Stack Exchange communities.

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?

Thanks!

share|improve this question
    
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. –  Uphill Luge Nov 14 '10 at 14:37
    
This is probably better suited to SO itself –  fahadsadah Nov 14 '10 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 '10 at 15:49
    
@Aarobot Question views aren't cached. They're handled using a buffered write system. –  Grace Note Nov 14 '10 at 16:04
    
@Grace: That's basically saying the same thing. –  Aarobot Nov 14 '10 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 '11 at 19:36
    
@GraceNote @Mohamad en.wikipedia.org/wiki/Data_buffer#Buffer_versus_cache –  Gilles Jul 11 '11 at 19:53
    
@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 Jul 11 '11 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 '11 at 19:56

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
    
Aren't you supposed to be on a plane :) –  waffles Nov 14 '10 at 16:51
    
does that mean you have a counter for every question? That's over 1 million counters :/ –  Mohamad Nov 14 '10 at 21:07
1  
@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 '10 at 18:46

You must log in to answer this question.

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