Search code examples
mysqlsqldatabasenormalization

How to store user activities in mysql database?


Consider a simple websites with lots of user activities (like stackoverflow). What is the best way to store user activities such as votes, adding to favorites, etc. To my knowledge there are two possible ways:

De-normalized: Storing user IDs of members who has voted for an article in a column for "who has voted" in the articles table. This will be comma-separated list of IDs.

Normalized: Creating a relationship table to connect article ID to user ID. This method has invaluable advantage (and I know most of you will support this idea); but my concern is (1) This table can easily reach millions of row. Since it is indexed, reading should be fast enough, but updating (on a regular basis) of a long indexed table can be problematic. (2) Every time visiting the article page, we need to read one more table which will slow down the regular queries.


Solution

  • You could also do the best of both worlds and have a transitional database and a rolled up reporting database that is refreshed "offline"