Facebook Interview Question
Software Engineer / DevelopersFor friends using Graphs as data structures seem a better option. hence forth referred to a YY.
1) Adding a friend needs an approval process, hence once someone adds X as a friend; we send an invite to X that you are interested. It means, updating the cache layer (so that you don't end up inviting the same person more than once) plus DB that an invite has been sent.
Deleting on the other hand has to instantaneously make changes to YY. Probably notify the friend that he has been deleted from your friend list.
2) Friend suggestions - is basically recommendations.
-> maybe you are from the same school/college/workplace etc. (distance 2)
-> maybe friends of friends from same school/college/workplace etc. (distance 2)
-> maybe you are a friend of your very popular friend.
-> import email addresses from your Gmail or other mail accounts.
As one can see all this recommendation list can be done offline & needs to be accessed when the user logs in.
3) Point mentioned by Akshat seems ok here.
In Facebook's infrastructure ALL (or most of it) exists in cache (i.e. RAM) for faster access. So one of the biggest challenges is to sync data between this cache layer & the actual mysql DB.
1) Link profiles together forming trees. Or linking nodes in Graph Matrix.
- Akshat Jain July 29, 20102) Friend suggestions can be made
a) If the given node is not already a friend
b) has a distance of 2 from the current Node
c) Has Maximum distinct routes of length 2 between them compared to other nodes
(Or has maximum common friends between them)
3) Make country specific or geographic servers for users.
Since friends tend to be geographically co-located.