Twitter: Interview Guide
Staff-Level Discussion Topics
These open-ended topics test architectural judgment. Practice explaining your reasoning out loud for each.
Real-Time Timeline Updates: Push vs. Pull Refresh
Currently, timelines are loaded on app open and paginated on scroll. For a more engaging experience, Twitter shows a "New tweets" indicator when fresh tweets arrive. How is this delivered?
Options:
- WebSocket/SSE: Server pushes "new tweets available" events to connected clients.
- Short polling: Client polls every 30 seconds for timeline updates.
- Long polling: Client holds an HTTP connection open; server responds when new data is available.
Search Architecture: Real-Time Tweet Indexing
Twitter search requires indexing 600M tweets/day in near-real-time. A search for "Super Bowl" during the game should show tweets posted seconds ago.
Key challenges:
- Indexing throughput: 7K tweets/sec must be tokenized, analyzed, and added to the search index.
- Inverted index storage: 600M tweets/day × 30 tokens/tweet = 18 billion index entries/day.
- Query latency: Search results must return in < 200ms.
- Relevance ranking: Balance recency with engagement signals.
Recommendation Algorithm: Beyond Chronological
Twitter's "For You" feed uses a recommendation algorithm that surfaces tweets from accounts the user doesn't follow. This is a fundamentally different pipeline from the follow-based timeline.
The staff challenge: designing a recommendation pipeline that processes billions of candidate tweets across 300M users, scores them in real time, and blends them with the follow-based timeline.
Level Expectations
| Area | Mid-Level (L4) | Senior (L5) | Staff (L6) |
|---|---|---|---|
| Requirements | Lists FRs (post, follow, timeline) and basic NFRs | Derives 7K write QPS, 700K read QPS; articulates 100:1 ratio implications | Fan-out write volume (1.4M cache writes/sec); inactive user optimization |
| Fan-out strategy | "Push tweets to followers" (fan-out-on-write) | Compares push vs pull; identifies celebrity problem; proposes hybrid | Calculates celebrity threshold; designs the merge pipeline; analyzes latency budget |
| Data model | Users/Tweets/Follows tables | Cassandra partition design; Snowflake IDs; timeline cache as Redis list | Compound partition keys for large accounts; tiered storage (hot, warm, analytics copy) |
| API Design | Basic CRUD endpoints | Cursor pagination; idempotency keys; async fan-out acknowledgment | Opaque cursor tokens; rate limiting semantics; API versioning |
| Architecture | Client → Service → DB | 3-service split; Kafka event bus; Redis timeline cache | Multi-region deployment; Redis cluster sizing math; Kafka consumer groups |
| Caching | "Use Redis" | Timeline cache structure; tweet content cache; TTL strategy | Redis cluster sizing (~220 nodes); stale-while-revalidate for timelines |
| Delivery guarantees | "Tweets should be delivered" | Retry-safe fan-out (dedupe on read); Redis failover; lazy deletion from cache | Consumer offset management; at-least-once vs exactly-once semantics |
Interview Cheatsheet
1. Opening Frame (30 seconds)
"Twitter is a 300M-DAU social platform where users post short messages and see a personalized feed. The core challenge is the timeline: assembling a feed from hundreds of followed accounts at 700K+ QPS. The architecture uses fan-out-on-write for regular users — tweets are pre-distributed to followers' Redis timeline caches via a Kafka-driven fan-out pipeline. Celebrities (>100K followers) use fan-out-on-read to avoid melting the write path. Timeline reads are a Redis LRANGE + hydration in under 200ms."
2. Requirements Scoping
- FRs: Post tweet, follow/unfollow, home timeline (paginated, ranked), user timeline
- NFRs: 300M DAU, ~7K write QPS (peak ~21K), ~700K read QPS (peak ~2.1M), <200ms timeline latency
- Consistency: Eventual for timeline; strong for tweet storage
- Out of scope: Search, DMs, media, notifications, trending topics
3. Core Architecture Components
- Tweet Service — stateless, writes to Cassandra, publishes to Kafka
- Follow Service — manages social graph in Cassandra
- Timeline Service — reads from Redis cache, hydrates tweets
- Fan-out Service — Kafka consumer, distributes tweet IDs to follower caches
- Cassandra — tweet storage + social graph, partitioned by author / user (followers bucketed)
- Redis — timeline cache (200 tweet IDs per user) + tweet content cache
- Kafka — event bus for TweetCreated events → fan-out, search, analytics
- ID Generation (Snowflake) — 64-bit, roughly time-sorted unique IDs
4. Key Trade-offs to Mention
- Fan-out-on-write vs read: Write (push) for regular users, read (pull) for celebrities. Hybrid is the sweet spot.
- Consistency: Pre-computed timeline is eventually consistent — acceptable for social media.
- Cassandra vs relational: Cassandra for write throughput and partition-key queries; no JOINs needed for our access patterns.
- Snowflake IDs vs UUID: Snowflake embeds timestamp → roughly time-sorted without secondary index.
- Cache size vs freshness: 200 tweet IDs per user balances memory (480 GB) with recency.
- Inactive user optimization: Skip fan-out for users inactive > 30 days (Twitter's cutoff); rebuild on login.

5. Numbers to Remember
| Metric | Value |
|---|---|
| DAU | 300M |
| Tweets per day | 600M |
| Read:write ratio | 100:1 |
| Write QPS (avg / peak) | 7K / 21K |
| Read QPS (avg / peak) | 700K / 2.1M |
| Fan-out cache writes/sec | 1.4M |
| Tweet size (with metadata) | ~480 bytes |
| Timeline cache per user | ~1.6 KB (200 IDs × 8B) |
| Total timeline cache | ~480 GB (300M users) |
| Redis cluster | ~220 nodes (110 primaries + 110 replicas) |
| 5-year storage | ~525 TB |
6. Possible Follow-up Questions
- "How would you handle trending topics?" — Real-time aggregation of tweet volume per hashtag using a sliding window counter in Redis. Kafka Streams for windowed counts.
- "How would you add retweets?" — A retweet is a new tweet with a
retweet_offield pointing to the original. Fan-out follows the same pipeline. - "How do you handle tweet editing?" — Store edit history in the tweet record. Invalidate the tweet content cache on edit. Timeline cache (which stores only IDs) is unaffected.
- "How do you prevent vote/like manipulation?" — One like per user per tweet: a likes table keyed by (tweet_id, user_id), so a second like overwrites the first. Rate limit likes per user per minute.
- "What about media (images/videos)?" — Upload to object storage (S3); a CDN (CloudFront) serves it. The tweet stores media_url. Fan-out and caching logic is identical — only the hydrated response includes media.