Prepin
Log in

Create a design for Twitter.

Approach / Explanation

This question essentially prompts you to explain how you would design a service similar to Twitter. The "Design Twitter" scenario is a common system design question in software engineering interviews, aimed at evaluating your understanding of system scalability, your ability to manage intricate systems, and your skill in navigating trade-offs. In your response, you should detail how you would approach various aspects of the system, including the data model, APIs, tweet distribution, timeline generation, notification system, and search capabilities. Ultimately, your answer should demonstrate your ability to effectively manage the system's scalability, reliability, and efficiency. Key considerations include: Data modeling and storage : Discuss which data storage method would be suitable, whether it's relational databases or NoSQL databases. Be sure to include sharding techniques for a distributed database. Tweet creation and distribution : Explain how you will manage incoming tweets and distribute them to users' followers. Timeline generation and delivery : Describe how you will create and deliver timelines to users. Scaling : Elaborate on how your design would scale to accommodate the near real-time nature of Twitter feeds. Search functionality : Describe how you would develop search features that filter the latest tweets based on specified keywords. Notification system : Discuss how you would implement a real-time notification system that alerts users when a follower posts a new tweet.

Suggested Answer

When designing a service similar to Twitter, I would begin by utilizing a NoSQL database such as Cassandra or DynamoDB to store tweets, as they provide high write throughput and horizontal scalability. This is essential given the large number of tweets that Twitter handles. To distribute new tweets to followers, I would consider implementing a Pub-Sub model . This model enables us to alert all followers whenever a tweet is posted, catering to the real-time aspect of Twitter feeds. An efficient method for generating user timelines could involve a precomputed timeline microservice . When a tweet is received, the application would update the timeline caches of all active followers. This cached timeline would allow for quicker read requests, creating the illusion of real-time updates. To ensure that our system can handle growth and sudden traffic spikes, we could introduce sharding . Sharding distributes the dataset across various databases, enhancing both write capacity and read performance. For the search functionality, I would implement an inverted index to facilitate rapid full-text searches. Additionally, the most recent tweets could be stored in a separate cache to improve search response times. Finally, establishing a push-notification system that integrates both email and app notifications would be vital. This could be accomplished using a service like Amazon's SNS (Simple Notification Service).

Alternative Answer

For a service similar to Twitter, it is essential to select a technology that can support high write throughput, making a NoSQL database a suitable choice for storing tweets. To distribute tweets, a push model can be implemented, where each time a user posts a tweet, it is sent to the timelines of all active followers, creating an experience akin to a real-time feed. Regarding the generation of timelines, an effective method is fan-out-on-write : when a user tweets, the tweet is promptly dispatched to a prepared list of their followers. If any follower is offline, the tweet can be flagged to be delivered when they log in. For scalability, consistent hashing should be utilized to manage rebalancing tasks like adding or removing servers. For search functionality, indexing can be accomplished using Elasticsearch , with tweets being allocated across various shards, each containing different partitions, and each partition can consist of one or more replicas. Finally, incorporating a notification system is important for alerting users about changes within their network, allowing them the choice to receive notifications via email or through the app.

Question Details

Difficulty & Category

Medium
system design

Companies

Twitter

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.