Facebook Interview Question
Software DevelopersCountry: United States
Interview Type: In-Person
message service->channel service<->push service<->client
friendship service
channel service stores if a user is online in memory.
When a user visits facebook homepage, message services returns a push server address to user and tells channel services and the user is subscribed for push. User then connects to the push server by socket.
When a user closes facebook, socket is disconnected. Push service tells channel service to unsubscribe the user.
When a comment is posted, message service send the comment to channel service. Channel service gets the thread followers and forward the comments only to those online through push service.
Push servers are sharded by userid with consistent hash
I wish I can add the graphical diagram in the answer.
Anyway, I will do my best.
It is frustrating to put textual diagram here though. Sorry for the messy diagram.
The followings are description of the components depicted in the diagram.
- hankm2004 October 20, 2015- Client A, Client B : represents client browsers
- Live feed router : is responsible for telling client which live feeder it should connect to.
it also checks the load level of live feeders. There can be mutiple live feed routers.
- Live feeder: is responsible for keeping COMET style push notification connection with the clients. Certain number of connections will be assigned by routers and it subscribes the changes that currently connected clients are interested from the message bus. This is either stateful or stateless. In case of the later, the client should keep track of which live feed it has now. We can assign GUID for each live feed.
- Message bus: is the intermediate channel allowing the application layer to publish the status change and live feeder to subscribe for the change.
Tricky part will be how we can handle too many subscribers for the celebrities who has lots of followers.
I think this can handled in many ways. For the simplicity, I would assume we set up the multi-layer subscription for these users' status.
- Application layer is business logic handling the write/read from the clients. Additional job this application layer also does is to publish the user's status to the message bus upon the write/update requests.
Assumptions made in this design are as follows:
-We don't develop push notification framework (a.k.a Commet)
-We have highly salable storage(DB) available.
Given that assumption, Live feeder, message bus, and Live feed router can be linearly scalable.