Reputation: 161
I am curious to know how a Entity relational Diagram would look for Facebook. I am a bit confused because there is an overlap between friends and a user, which causes duplicate data entries in the database.
A user can make a post, and can have many friends
however,
A friend can also make a post and have friends of their own
How would you design a schema for a social media application such as facebook?
Thank you!
Upvotes: 1
Views: 2914
Reputation: 4350
A user
can creates many post
.
A user
can have many friends
. First, this relationship is a many-to-many relationship on user
. Then we can map it as a new entity and named it friends
with two F.K from user
. For example it can save that user1 and user2 are friends.
A friend
is a user
too. So he/she (as a user
) can creates post
s too.
The ER in UML notation can be like below:
Note that, this ER shows that user1 is a friend to user2 (not vise versa). But from meaning of friendship, we can result that user2 is friend of user1 too.
Additionally, Friends relationship is a graph relationship between users. In ordinary projects above ER is good. But in big and real projects you can use Graph Databases like neo4j.
Upvotes: 1
Reputation: 589
I would imagine something a little like;
User table - user details
Post table - owned by a user
Friends table - a table that stores the link between people.
Upvotes: 1