Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
POST /api/twitter/tweet
Authorization: Bearer
{
content: str[140]
} -> Tweet
POST /api/twitter/follow
{
user_id: str
}
POST /api/twitter/like/:tweet_id
{
}
GET /api/twitter/feed?count=...
-> List[Tweet]
Tweet {
tweet_id: str
content: str[140]
like_count: int
}
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
For the design we need a DNS server to provide a user-friendly address and also to geoproximity routing and load balancer failover.
I have devided the designs into 3 main services:
Follow service receives requests for following a friend and adds it to Neo4j Graph database.
Tweet Service is used for posting a tweet, it uses a distributed ID Generator (I assumed we have it) to generate the id for the tweet the posts the tweet in a NoSQL database such as MongoDB. It also pushes the tweetId and content to Kafka. Tweet Service only pushes to Kafka if the user is not a celebrity.
Workers listen to Kafka and take the tweetId and content and push them to Redis.
Redis is sharded by user_id, so every user will have a cached list of the tweets of their friends.
Feed Service is used to display the top K tweets. It fetches the data from redis then combines it with the data fetched directly from MongoDB which corresponds to celebrities.
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Follow Service:
Tweet Service:
Feed Service: