Потоки / каналы активности, денормализовать или нет?

Я знаю, что варианты этого вопроса задавались много раз до (и я их читал, два из них: 1 , 2 ) , но я просто не могу осмыслить то, что кажется правильным решением.

Было предложено все: от многих ко многим отношениям, до разветвления, до полиморфных ассоциаций, до решений NoSQL, до очередей сообщений , денормализации и их комбинаций.

Я знаю, что этот вопрос очень ситуативный, поэтому я кратко объясню свой:

  • Многие действия, которые вызывают множество событий.
    • После создания, добавления лайков, комментирования, редактирования, удаления и т. Д.
  • Пользователь может отслеживать действия другого пользователя (события, которые они запускают) .
  • Наиболее запрашиваемыми событиями будут события самые последние события.
    • The ability to view past events is desired.
  • No sorting or searching of the feed is desired past ordering by date desc.
  • Scalability is a concern (performance and expandability).

For the mean time, I ended up going with a denormalized setup basically being made up of an events table consisting of: id, date, user_id, action, root_id, object_id, object, data.

user_id being the person that triggered the event.
action being the action.
root_id being the user the object belongs to.
object being the object type.
data containing the minimum amount of information needed to render the event in a user's stream.

Then to get the desired events, I just grab all rows in which the user_id is the id of a user being followed by whose stream we're grabbing.

It works, but the denormalization just feels wrong. Polymorphic associations seem similarly so. Fanout seems to be somewhere in between, but feels very messy.

With all my searching on the issue, and reading the numerous questions here on SO, I just can't get anything to click and feel like the right solution.

Any experience, insight, or help anyone can offer is greatly appreciated. Thanks.

17
задан Community 23 May 2017 в 12:30
поделиться