Twitter API Design
Explore the design of Twitter's API focusing on key functionalities like posting tweets, viewing timelines, and searching content. Understand how RESTful principles, HTTP/2, pub-sub services, and caching strategies contribute to a scalable, reliable, and responsive system. This lesson helps you analyze API decisions for complex social platforms and estimate latency budgets to meet user expectations.
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?
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, ...