Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Followers' and efficiency

I am designing an app that would involve users 'following' each other's activity, in the twitter sense, but I am not very experienced with database/query design/efficiency. Are there best practices for managing this, pitfalls to avoid, etc.? I gather this can create a very large load on the db if not done properly (or maybe even then?).

If it makes a difference it is likely that people will 'follow' only a relatively small number of people (but a person may have many followers). However this is not certain, and I wouldn't want to count on it.

Any advice gratefully received. Thanks.

like image 805
Chris Avatar asked Jul 29 '10 08:07

Chris


2 Answers

Pretty simple and easy to do with full normalisation. If you have a table of users, each with a unique ID, you would have a TABLE_FOLLOWERS table with the columns, USERID and FOLLOWERID which would describe all the followers for each user as a one to one to many relationship.

Even with millions of assosciations on a half decent database server this will perform well and fast as long as you are using a good database (IE, not MS-Access).

like image 119
Tom Gullen Avatar answered Sep 28 '22 00:09

Tom Gullen


The model is fairly simple. The problem is in the size of the Subscription table; if there are 1 million users, and each subscribes to 1000, then the Subscription table has 1 billion rows.

follower_model.png

like image 30
Damir Sudarevic Avatar answered Sep 28 '22 00:09

Damir Sudarevic