Design Twitter-like system
Problem Statement
Design a Twitter-like system that allows users to:
The system must ensure high availability, low latency, and scalability across global regions.
✅ Functional Requirements
👤 User Features
⚙️ Non-Functional Requirements
Category and Requirement
Scalability
Must handle millions of active users and billions of tweets.
Availability
99.99% uptime globally.
Latency
Timeline generation <200ms.
Consistency
Eventual consistency for feed updates.
Durability
Tweets and user data must not be lost.
Security
Authentication, authorization, and secure data storage.
Storage
Efficient handling of large tweet, user, and media datasets.
🧩 Core Components
Component with Description
User Service
Handles user profiles, authentication, and relationships (follows/unfollows).
Tweet Service
Manages creation, deletion, and retrieval of tweets.
Feed Service
Generates and caches user timelines.
Notification Service
Sends alerts for likes, retweets, replies, or follows.
Media Service
Stores and serves images/videos (via S3/CDN).
Search Service
Supports full-text and hashtag-based searches (ElasticSearch).
Analytics Service
Tracks trends, engagement, and user metrics.
Cache Layer
Stores hot data (recent tweets, timelines) in Redis or Memcached.
Database Layer
Stores persistent data — tweets, users, relationships.
Message Queue
Manages asynchronous tasks like fan-out and notifications.
🧱 High-Level Design Considerations
🧠 Architecture Overview
⚡ Key System Challenges & Trade-offs
| Challenge | Design Choice / Trade-off |
| **Feed scalability** | Hybrid fan-out model (mix of write/read fan-out). |
| **Hot users with millions of followers** | Use lazy loading or separate fan-out queue. |
| **Data partitioning** | Shard tweets and relationships by user ID. |
| **Timeline freshness** | Use cache invalidation and background refresh. |
| **High availability** | Use replication and distributed databases. |
| **Read-heavy workload** | Use aggressive caching and precomputed timelines. |
🧠 Discussion Points (Interview Focus)
🧾 Final Interview Prompt
Design a Twitter-like System that enables users to post tweets, follow others, view a personalized feed, like/retweet/reply to tweets, and search for content.
The system should handle millions of concurrent users, scale globally, and maintain low latency for reads and writes.
Discuss architecture, database schema, feed generation strategies, and scalability mechanisms.