How to handle massive storage of records in database for user authorization purposes?

后端 未结 7 1755
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 09:30

I am using Ruby on Rails 3.2.2 and MySQL. I would like to know if it is \"advisable\" / \"desirable\" to store in a database table related to a class all records related to

7条回答
  •  礼貌的吻别
    2021-01-05 09:57

    The fact of the matter is that if you want article-level permissions per user then you need a way to relate Users to the Articles they can access. This neccesitates a minimum you need N*A (where A is the number of uniquely permissioned articles).

    The 3NF approach to this would be, as you suggested, to have a UsersArticles set... which would be a very large table (as you noted).

    Consider that this table would be accessed a whole lot... This seems to me like one of the situations in which a slightly denormalized approach (or even noSQL) is more appropriate.

    Consider the model that Twitter uses for their user follower tables:

    Jeff Atwood on the subject

    And High Scalability Blog

    A sample from those pieces is a lesson learned at Twitter that querying followers from a normalized table puts tremendous stress on a Users table. Their solution was to denormalize followers so that a user's follower's are stored on their individual user settings.

    Denormalize a lot. Single handedly saved them. For example, they store all a user IDs friend IDs together, which prevented a lot of costly joins. - Avoid complex joins. - Avoid scanning large sets of data.

    I imagine a similar approach could be used to serve article permissions and avoid a tremendously stressed UsersArticles single table.

提交回复
热议问题