Interview question: Design Twitter.
This was a system design question, and the overall task was simply to design Twitter/X.
They first asked about the basic functional requirements:
- Create an account
- Let users post tweets
- Follow and unfollow users
- View the home timeline
- Like and retweet
- Comment
- View trending or popular tweets
Then they asked me to draw the overall architecture and the core entities. We discussed User, Tweet, Follow, Like, Retweet, Comment, and related entities.
The main focus was still the home timeline. They asked how the timeline would be generated and how it would scale as the number of users and tweets increased. We discussed fan-out on write and fan-out on read, along with special handling for users with very large followings.
Later there were several high-concurrency follow-ups. For example, if a popular user posts a tweet and a huge number of users may need to see it immediately, how do you keep the database from being overwhelmed? We also discussed how the timeline could use Redis or another cache for optimization.
We also discussed how to implement trending or popular tweets, and how to maintain performance for high-concurrency reads and writes involving likes and retweets.
Finally, they focused on high availability and horizontal scaling, including stateless services, caching, database sharding and replication, and how to keep the system working after one component fails.
Overall, this felt like a classic question. The important parts were the timeline, high concurrency, trending content, and high availability.
Discussion
Loading comments…