View
You get to the comment page. The comment voting system is highlighted with your votes.

Database
To support this requirement, the database schema will look at a minimum:
Page
Comments
Votes
- int userId
- int commentId
- listing (up, down)
Controller
If the page ID was 123 and the user ID was 456, this would be a naive controller implementation:
1) Request all votes made by user 456 in the comments on page 123:
SELECT c.commentId, v.direction FROM comments AS c, votes AS v WHERE c.pageId = 123 AND c.commentId = v.commentId AND v.userId = 456
2) Build a view with the results of this query.
Scalability issue
Querying a database to support this voting system is very expensive. The table of comments and votes will be huge. On a site with high traffic, thousands of users will execute this request every second to get a personalized view of the voting by comments. How do you scale this voting system so that the database is not overloaded with too many queries? Would you cache it in memory? Isn't it a betting practice to cache things common to a large audience? In this case, these queries apply to individual users. The memory will quickly be full on the website by millions of users. Cache skips will occur and the database will be crashed.
source share