POST /v1/tweets
request: {
"user_id": "123",
"content": "Hello Twitter!",
"media_ids": ["m1", "m2"]
}
Response: {
"tweet_id": "t456",
"created_at" "2026-02-02T10:00:00:00Z"
}
POST /v1/tweets/{tweet_id}/like
Request: { "user_id": 123" }
Response: {"success": true }
POST /v1/users/{user_id}/follow
Request: {"follower_id": "123"}
Response: {"success: true}
GET /v1/timeline/home?user_id=123?cursor=abc?limit=20
Response: {
"tweets": [
{
"tweet_id": "t789",
"user_id": "456",
"username": "john doe",
"content": "...",
"created_at": "...",
"likes_count": 100,
"retweets_count": 50
}
],
"next_cursor": "xyz"
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
Purpose: Entry point for all client requests
Responsibilities:
Purpose: Handle all tweet-related operations
Key Functions:
Responsibilities:
Purpose: Generate and serve user timelines
Key Functions:
Responsibilities:
Purpose: Persistent storage for all tweets
Why Cassandra?
Purpose: Fast in-memory storage for pre-computed timelines
Why Redis?
Data Structure:
Key: timeline:{user_id}
Value: ZSET {tweet_id: timestamp}
Operations: ZADD (insert), ZREVRANGE (get latest)
Cache Strategy:
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Purpose: Entry point for all client requests
Responsibilities:
Purpose: Handle all tweet-related operations
Key Functions:
Responsibilities:
Purpose: Generate and serve user timelines
Key Functions:
Responsibilities:
Purpose: Persistent storage for all tweets
Why Cassandra?
Purpose: Fast in-memory storage for pre-computed timelines
Why Redis?
Data Structure:
Key: timeline:{user_id}
Value: ZSET {tweet_id: timestamp}
Operations: ZADD (insert), ZREVRANGE (get latest)
Cache Strategy:
Fanout-on-Write:
Fanout-on-Read:
Chosen: Hybrid approach balances both
SQL (PostgreSQL):
NoSQL (Cassandra):
Push (Fanout-on-write):
Pull (Fanout-on-read):