Data modeling for social media followers/following... bucket pattern?

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?

Following up to see if anyone has any suggestions on this.

To summarize the questions above, is there a recommended approach or pattern for handling large amounts of follower/following relationships between users in a social media context using MongoDB?

I found the answer here referencing the socialite project:

For anyone else who comes across this, it looks like the suggested approach is to store each follow relationships as one individual document per relationship. So, two collections as noted above, but no bucket pattern, just individual follower or following documents.


If you ever considered setting the maximum number of followers and subscriptions for each user?

It can be a really good feature, and today many people are using social media accounts only to gain followers, so if you plan to make a social media application, it can be a good feature if you get a decent explanation. This feature may define your social media project from other platforms like TikTok or Instagram, where all content creators try getting followers with all possible tools, including promotional services like