Database design for a social networking site

DatabaseDatabase DesignSocial Networking

Database Problem Overview


What are the Tables that would be present in a social networking site (ex: Twitter).

I have a users table as of now. How to keep track of followers and people I do follow?

  • Should I maintain a separate table for followers and people I follow?
  • What are the columns which would be there in those tables?

Please don't think this as Subjective/Off topic. As I am a beginner, I thought experts can guide me to get a good DB design?

Database Solutions


Solution 1 - Database

Try having a look at Database Answers in particular the data models. They have several different designs for various systems. This one is for a social networking site which may give you an idea of what's required.

You may want to search on SO for other social network database questions. I found this one that had a link to flickr showing a schema which appears to be from Facebook.

Your database design will be based around your system requirements. Without knowing exactly what you are trying to achieve, it is difficult to give you the best design.

Solution 2 - Database

You can create a separate table for follower/ followed relationships. So, when x follow y, create an entry with follower_id = x.id followed_id = y.id.

You can query the relationship table to look for all the users x has relations with by select * from relationships where follower_id = x.id or vice versa.

When/if x un-follow y, you just have to delete the entry you originally created.

Solution 3 - Database

you can use this Messenger Database Design Concept: Messenger DB

Messenger DB Schema

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser326638View Question on Stackoverflow
Solution 1 - DatabaseAndy RobinsonView Answer on Stackoverflow
Solution 2 - Databaseuser3375663View Answer on Stackoverflow
Solution 3 - DatabaseSadegh-khanView Answer on Stackoverflow