What I’m looking to create is a follower / following system where instead of simply following a user, you’re following sections of content they share. Almost as if you were following Twitter’s “Lists” or Groups rather than the people. Though, with this you’d be able follow/unfollow everything a user is sharing or just follow/unfollow the lists that you want.
Ex #1: I click a “follow all” button to follow User #1’s lists but unfollow the one about politics. Now I’m following all of what they are sharing except one list. I am a follower of them.
Ex #2: I follow only one of User #2’s lists instead of clicking the “follow all” button. I should only see the one list and not all of their lists.
The structure for a simple follow/following system may be a table with user_id => follower_id schema, but that wouldn’t account for the new lists created by the user that one follows.
Question: What database schema would suit this best?
To simplify it and to help it scale, I would think of it as a mapping of
list_id => follower_idwith a helper table that is a mapping ofuser_id => follower_idThe only thing the helper table would let you know is that if the user creates a new list, it tells you what
list_id => follower_idmappings you need to create. It basically just serves as a setting for the follower. (Ex: Automatically follow X user’s new lists)When you are displaying the feed to the follower you would only access the table that has the map
list_id => follower_id. You wouldn’t even need to look up theuser_id => follower_idmapping. That only comes in to play when a new list is created.The biggest problem here is that you have to handle the case where the follower says “Follow All”/”Follow User” for the first time. In this case you would backfill all of the
list_id => follower_idmappings based on what lists already exist for that user. (I believe this is similar to how Twitter handles their following model. If I start to follow someone it backfills an X number of their tweets and if I unfollow it removes an X number of their most recent tweets)Then, if the user wants to exclude a list, you just remove the mapping for that specific list to that follower. You can leave the mapping of
user_id => follower_idin this case because I’m assuming you want any new lists the user creates to show up for the follower.