Twitter API Design
Explore the design of the Twitter API, including how tweets are created, timelines generated, and services interact. Understand the architectural choices, communication patterns, and nonfunctional requirements such as scalability, availability, security, and low latency. Learn how core endpoints, message formats, and caching strategies support a responsive user experience for millions of active and inactive users.
Twitter API design
Twitter is a platform where millions of users share
Functional requirements
Post a tweet: Allow users to post tweets containing text, images, videos, or non-executable documents.
View timeline: Enable users to retrieve their timelines.
Search: Enable users to search for any tweet or account.
Comment on a tweet: Allow users to comment on a tweet.
Rate a tweet: Allow users to like or unlike a tweet.
Note: Most core functionality requires user authentication. Some of the functionality mentioned above is available as pre-built building blocks.
How would you enable fast, scalable tweet and account search in Twitter's architecture without affecting real-time operations?
Use the AI assessment widget below to submit your solution and get an interactive response.
Nonfunctional requirements
Availability: High availability for end users.
Reliability: Graceful degradation; users should be able to view tweets even if posting is temporarily unavailable.
Scalability: Handle ever-increasing user and request volumes.
Security: Secure storage and communication of user data.
Low latency: Near real-time response times for a smooth user experience.
Prerequisites
Several Twitter features leverage existing building blocks:
Search API: Finds tweets or entities based on a search query.
Comment API: CRUD operations on tweet comments.
Rating API: Allows users to rate tweets.
Pub-sub API: Notifies the timeline service about newly posted tweets.
File upload API: Handles media file uploads.
Design overview and decisions
With requirements established, understanding the end-to-end architecture is essential before making design decisions. The Tweet service handles the creation and storage of new tweets, while the timeline service generates timelines by interacting with multiple components: timeline generation, ...