I'm looking for a simple way to store and retrieve a count for however many times a user views a unique post/page. ex post/1 post/2. And I'm also interested in a total view count of a post.
How I think I should implement this:
- Create userpostview table with columns (userid,postid,datecreated)
- Create row of userpostview every time with userid,postid if record does not exist
- Retrieve total count of rows where userid == X
- Retrieve total count of rows where postid == Y
For a small scale app with a few rows is okay. But I'm anticipating a high percentage of different users reading different posts per day. Therefore, the userpostview table would be much greater than that of either user table or post table. In the long run, I believe this will be a performance problem, correct? For instance calling on counts continuously could slow down the read. I'm wondering if caching the count would be ideal in this situation. Or should there be a separate table to hold a incremental counter?
I'm using flask with a sqlalchemy backend to postgresql. Is this sufficient?
However after doing a bit of research, I saw this:
https://www.youtube.com/watch?v=G-lGCC4KKok
http://highscalability.com/blog/2012/3/26/7-years-of-youtube-scalability-lessons-in-30-minutes.html
Should I be "faking" the counter? Is there a better approach? Any better or improved suggestions are welcomed.
Thanks in advance.