I want to implement a user-facing view counter (similar to what SO has for question views) that tracks the number of unique views to a page. There are a couple of similar questions here but none seem to answer my question fully.
What would be the best setup for this (in terms of database tables etc.)? Would it be good to add a 'views' column to the 'questions' table and simply increment this upon every page view? And if I want the views to be unique, I guess I could have another table with question id's and IP addresses and only increment the 'view' column if there isn't already an entry with the current IP. However this 'ip-view' table would get enourmous really quickly...Mainly I am concerned with the overhead of having to store every page view and every IP in a table.
How could this be optimized so that it doesn't become a performance bottleneck? Is there a better approach than what I described? Please note that it is very important for me that only unique views are counted.
Update: in addition to suggesting implementation methods, I'd also like to further understand where the performance issues come into play assuming the naive approach of simply checking if the IP exists and updating the 'view' column on every page view. Is the main issue vast amount of insertions occuring (assuming heavy traffic) or is it more the size of the object-to-ip mapping table (which could be huge since a new row will be inserted per question for each new unique visitor). Should race conditions be considered (I just assumed that an update/increment sql statement was atomic)? Sorry for all the questions but I am just lost as to how I should approach this.