Search⌘ K
AI Features

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 tweetsA Tweet can contain text, images, or videos., and billions react daily. Behind the interface, multiple services and components interact to create tweets, generate a timelineThe timeline includes a stream of Tweets and various recommendations based on the user's interests and followers' activity (such as their Tweets, Retweets, likes, etc.)., and perform other tasks. Designing its API requires a deep understanding of the backend system.

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.

Functional and nonfunctional requirements of the Twitter API design
Functional and nonfunctional requirements of the Twitter API design

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.

Scalable Tweet Search

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:

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, ...

The end-to-end architecture of the timeline and Tweet services
The end-to-end architecture of the timeline and Tweet services
...