News feed database design as in Facebook

后端 未结 3 2076
难免孤独
难免孤独 2021-02-04 13:20

How would make a news feed \"friendly\" database design, so that it wouldn\'t be extremely expensive to get all of the items (query) to put in the news feed? The only way I can

3条回答
  •  自闭症患者
    2021-02-04 14:14

    Firstly, consider doing a performance prototype to check your hunch that the union would be too expensive. You may be prematurely optimisizing something that is not an issue.

    If it is a real issue, consider a table designed purely to hold the event feed data, that must be updated in parallel with the other tables.

    E.g. when you create a Note record, also create an event record in the Event table with the date, description, and user involved.

    Consider an indexing the Event table based on UserId (or UserId and Date). Also consider clearing old data when it is no longer required.

    This isn't a normalised schema, but it may be faster if getting an event feed is a frequent operation.

提交回复
热议问题