Crushing Tech Education

Crushing Tech Education

Share this post

Crushing Tech Education
Crushing Tech Education
Twitter System Design
Copy link
Facebook
Email
Notes
More
User's avatar
Discover more from Crushing Tech Education
Join a community of engineers and technical managers dedicated to learning System Design.
Over 3,000 subscribers
Already have an account? Sign in
System Design

Twitter System Design

Design a Twitter timeline generation and posting a tweet functionality

SWE's avatar
SWE
May 03, 2023

Share this post

Crushing Tech Education
Crushing Tech Education
Twitter System Design
Copy link
Facebook
Email
Notes
More
Share

Before discussing the overall system architecture, it is important to consider these different user categories and how we can best serve each group while maintaining optimal performance.

Famous Users are typically high-profile individuals such as celebrities, sportspeople, politicians, or business leaders who have a substantial number of followers.

Thanks for reading Crushing Tech Interview! Subscribe for free to receive new posts and support my work.

Active Users are those who have accessed the system within the last few hours or days. For our purposes, we will consider individuals who have accessed Twitter within the last three days as active users.

Live Users are a subset of active users who are currently using the system, similar to those online on Facebook or WhatsApp.


When a user submits a tweet, the tweet processor service saves the tweet in a permanent data store, using Cassandra due to its efficiency in handling a large volume of tweets and query patterns.

The tweet processor service is responsible solely for posting tweets and does not expose any GET APIs for retrieving them. Upon posting a tweet, the tweet processor service sends an event to Kafka indicating the tweet ID and user ID. A tweet service is deployed on top of Cassandra that exposes APIs for fetching tweets by tweet or user ID.

Now let's consider the user's perspective. On the read-flow, users can view their user timeline (tweets from that user) or home timeline (tweets from people they follow). Given that a user could follow many users, querying all the relevant information at runtime could delay rendering. To address this, we cache the user's timeline, pre-calculating the timeline of active users and caching it in Redis. This can be achieved using a timeline processor. As a result, active users can instantly view their timeline.


We have examined how the system handles active users, but how can we optimize the flow for live users? As previously mentioned, when a tweet is posted, an event is sent to Kafka, which communicates with the tweet processor to generate timelines for active users and store them in Redis. However, if the tweet processor detects that a user who requires an update is live, it will trigger an event to Kafka, which will then interface with the live websocket service mentioned earlier. This websocket service will send a notification to the app and update the timeline in real-time.

Here's the video of me explaining the design 👇‍

Thank you for reading this edition of the newsletter!

Thanks for reading Crushing Tech Interview! Subscribe for free to receive new posts and support my work.

Share this post

Crushing Tech Education
Crushing Tech Education
Twitter System Design
Copy link
Facebook
Email
Notes
More
Share

Discussion about this post

User's avatar
Starting an Architecture Review Team
How to start, manage, and deliver!
Feb 25, 2024 • 
SWE
 and 
Fran Soto
13

Share this post

Crushing Tech Education
Crushing Tech Education
Starting an Architecture Review Team
Copy link
Facebook
Email
Notes
More
3
Design a Coding Contest Platform like Leetcode
Remote code execution engine and database design.
Feb 3, 2024 • 
SWE
12

Share this post

Crushing Tech Education
Crushing Tech Education
Design a Coding Contest Platform like Leetcode
Copy link
Facebook
Email
Notes
More
6
Design Stock Exchange | HLD | Data Model | Reliability
Design a stock exchange, process buy and sell orders efficiently in memory
Jan 6, 2024
2

Share this post

Crushing Tech Education
Crushing Tech Education
Design Stock Exchange | HLD | Data Model | Reliability
Copy link
Facebook
Email
Notes
More

Ready for more?

© 2025 Crushing Tech Education
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More

Create your profile

User's avatar

Only paid subscribers can comment on this post

Already a paid subscriber? Sign in

Check your email

For your security, we need to re-authenticate you.

Click the link we sent to , or click here to sign in.