Design the full backend architecture for Twitter (X) - one of the most iconic system design problems. The platform serves 500 million monthly active users posting 500 million tweets per day. Your design must cover:
- Tweet creation & storage - users post tweets (up to 280 characters, optionally with images/videos). Tweets are immutable once posted (edits create a new version linked to the original).•Home timeline generation - the most critical feature. When a user opens the app, they see tweets from people they follow, ranked by relevance. The fan-out problem is central - a celebrity with 50 M followers posting a tweet must not cause a write storm to 50 M timelines.•Search - real-time full-text search over all tweets, with filtering by recency, popularity, and user. Results in < 300 ms.•Trends - detect trending topics/hashtags globally and per-region using sliding-window analytics, updated every minute.•Notifications - likes, retweets, mentions, and new followers trigger push notifications.•Media delivery - images and videos are served via CDN. Videos are transcoded into multiple resolutions.
Think about the hybrid fan-out model: fan-out-on-write for normal users (~1,000 followers) and fan-out-on-read for celebrities (~50 M followers).
Design the architecture behind Twitter - tweets, timelines, trends, and search at 500 M+ users. Build this architecture under realistic production constraints, then validate tradeoffs in the design lab simulation.
Request path: The solution keeps ingress, service logic, and stateful dependencies separated so each layer can scale independently.
Reference flow: Web Clients -> DNS -> CDN Edge -> Load Balancer -> Core Service -> Primary NoSQL DB -> Redis Cache -> Message Queue