← Back to All Questions
Medium~60 minSocial Media

Design Twitter/X - Social Media Platform

TwitterMetaGoogleAmazonMicrosoftLinkedInTikTok

📝 Problem Description

Design a social media platform like Twitter/X that allows users to post short messages (tweets), follow other users, and view a personalized home timeline. The system should handle hundreds of millions of users with real-time tweet delivery and support features like likes, retweets, and replies.

👤 Use Cases

1.
User wants to post a tweet (280 characters) so that the tweet is visible to their followers
2.
User wants to follow another user so that they see that user's tweets in their timeline
3.
User wants to open their home timeline so that they see recent tweets from people they follow
4.
User wants to like or retweet a tweet so that the engagement is recorded and visible
5.
User wants to reply to a tweet so that their reply is threaded under the original tweet
6.
User wants to search for tweets or users so that they find relevant content

✅ Functional Requirements

  • Users can post tweets (280 characters max) with optional media
  • Users can follow/unfollow other users
  • Users can view their home timeline (tweets from followed users)
  • Users can like, retweet, and reply to tweets
  • Users can view any user's profile and their tweets
  • Users can search for tweets and users
  • Real-time notifications for mentions and interactions

⚡ Non-Functional Requirements

  • Home timeline should load in <500ms
  • New tweets should appear in followers' timelines within 5 seconds
  • Support 500M daily active users
  • Handle 500M tweets per day
  • High availability (99.99% uptime)
  • Eventually consistent (timeline can be slightly delayed)

⚠️ Constraints & Assumptions

  • Tweet size: 280 characters text + optional media (up to 4 images or 1 video)
  • Users can follow up to 5000 accounts
  • No limit on followers (celebrities have 100M+ followers)
  • Timeline shows last 800 tweets from followed users
  • Read-to-write ratio approximately 1000:1

📊 Capacity Estimation

👥 Users
500M DAU, 1B total registered users
💾 Storage
~500TB/year for tweets (500M tweets/day × 1KB × 365 days)
⚡ QPS
Timeline reads: 500K/sec, Tweet writes: 6K/sec
🌐 Bandwidth
50TB/day for timeline reads
📐 Assumptions
  • 500M daily active users
  • 500M tweets per day (1 tweet per active user)
  • Average user reads timeline 10 times per day
  • Average user follows 200 accounts
  • Average celebrity has 1M followers, top celebrities have 100M+
  • Media storage: 50TB/day for images and videos

💡 Key Concepts

CRITICAL
Fan-out on Write
When a user tweets, push to all followers' timelines immediately. Fast reads, but expensive writes for users with many followers.
CRITICAL
Fan-out on Read
For celebrities with millions of followers, don't push. Pull their tweets when a follower reads their timeline. Avoids write amplification.
CRITICAL
Hybrid Approach
Use fan-out-on-write for users with <10K followers, fan-out-on-read for celebrities. Best of both worlds.
HIGH
Timeline Cache
Pre-computed timelines stored in Redis as list of tweet_ids. Keeps last 800 tweets per user.
HIGH
Social Graph
Follow relationships stored in graph database for efficient traversal. Critical for fanout operations.
HIGH
Event-Driven Architecture
Kafka decouples tweet creation from fanout, notifications, and search indexing.

💡 Interview Tips

  • 💡Start by clarifying the scale - number of users, tweets per day, follows
  • 💡Identify the "celebrity problem" early - it's the key challenge
  • 💡Explain fan-out strategies in detail with trade-offs
  • 💡Draw the timeline generation flow
  • 💡Discuss caching extensively - it's critical for performance
  • 💡Mention Kafka for decoupling - shows production experience
  • 💡Be prepared to discuss trending topics and content moderation
  • 💡Cover the algorithmic timeline vs chronological timeline trade-off