Interview Bootcamp
Ask Author
Back to course home

0% completed

Vote For New Content
In Instagram or Twitter design, why does the user follow table use PK as both fo...

Krispy Donut

Jan 26, 2022

In Instagram or Twitter design, why does the user follow table use PK as both follower and followed? How can I use such a table to find all followers or all followed of a single user?

0

0

Comments
Comments
G
Guy Shenker4 years ago

The PK has to combine both fields because a given user id, easier as the follower or the one who's followed may show up multiple times because many people follow me and I follow many people (thus not providing the One-of-a-kind attribute of a PK). If you would like to k...

H
henry gupta4 years ago

what is the reason for egress and ingress calculation where does it help overall.

C
calvio 2 years ago

it is a composite key, comprised of both follower + followee columns. they're both indexed so you can simply query like SELECT FollowerID FROM Followers Table WHERE UserID = 'User A';