Prepin
Log in

P

Create a simplified version of the Twitter Timeline.

Approach / Explanation

This system design question requires you to create a simplified model of the Twitter Timeline. The Twitter Timeline is the collection of tweets displayed to a user upon logging into Twitter, which includes posts from accounts they follow, along with potentially recommended tweets aligned with their interests. The interviewer aims to evaluate your grasp of distributed systems, database creation and management, as well as your approach to managing large data volumes and real-time requests. You should take into account aspects such as data sharding, caching, database indexing, API design, data propagation delays, scalability, and fault tolerance.

Suggested Answer

Creating a timeline similar to Twitter requires several components that work together. At a broad level, we can pinpoint three essential services: User Service : This service oversees user profiles and their following relationships. When a user decides to follow another, it must update the following and follower lists for both users within the system. Tweet Service : This service is responsible for creating, reading, and deleting tweets. Once a tweet is posted, it should be immediately distributed to the timelines of all followers. Timeline Service : This service aggregates tweets from users that a person follows and displays them in reverse chronological order. It should be updated almost in real-time whenever someone the user follows posts a tweet. To manage the substantial number of tweets and users on the platform, we could opt for a distributed database for data storage. Additionally, employing a shared-nothing architecture would allow us to spread the data and workload across several servers while ensuring that each server functions independently. For the timelines, we might implement a fan-out strategy, where the timeline keeps a list of tweet IDs from users that the individual follows. When a user tweets, the service distributes the tweet to the timelines of all followers, facilitating real-time updates. Given the significant volume of reads, caching could be crucial for enhancing system performance.

Alternative Answer

At a high level, the system design could consist of three primary components: User Service : This service manages user accounts, including tracking follower relationships. When one user starts following another, the User Service updates that user's feed in the Timeline Service. Tweet Service : This component is in charge of creating, deleting, and retrieving tweets. When a user posts a tweet, the Tweet Service notifies the Timeline Service to distribute the new tweet to the relevant user feeds. Timeline Service : This service compiles a user's feed by gathering tweets from the accounts that the user follows. Given the need to manage a significant amount of data, using a distributed database would be a wise decision for storing user profiles, tweets, and follow relationships. A system like Cassandra could be employed due to its capacity to handle a high volume of writes. To enhance speed, the Timeline Service may adopt a fan-out approach. When a user tweets, that tweet is instantly added to the timelines of all their followers. Additionally, to improve access times, we can cache the most recent tweets, as most users tend to view the latest content. To ensure consistency in a distributed setting, we might implement eventual consistency, allowing time for writes to propagate, which is generally acceptable since users typically tolerate minor delays in tweet visibility.

Question Details

Difficulty & Category

Medium
system design

Companies

Better.com
Peloton

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

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