Hi, I’m working on implementing social functionality in an app where users can follow each other. I’m trying to come up with a good approach for storing these follower/following relationships between users.
I was initially going to use two collections… Follower and Following where each document would contain a user id, and an array of users the person is following, or who are following them.
My concern with this approach is that if follower count gets very large, we will hit the 16mb BSON limit. An alternative would be having one document per follower relationship, which introduces other performance issues.
Is a bucket pattern the best solution for this… or is there a better approach? I could have buckets of 100 followers and then also use those buckets for paginating lists of followers to display.
However my concern is that when deleting a follower… all buckets for a given user would have to be searched and then when the follower is removed, an old bucket might have a gap. This gap could then be filled by a new follower in the future, but this would mean it would be more difficult to display the followers in order of new to old without sorting on date followed, which I imagine could become a performance issue.
I’m relatively new to MongoDB and learning. This great article by @Justin mentions that this bucket gap issue can be solved by expressive update instructions introduced in MongoDB 4.2, but I’m having trouble understanding how this would resolve the issue:
Any suggestions for using MongoDB when dealing with potentially large and ever growing social data like this?