Loading...
Loading...
Design a social networking news feed similar to Facebook's News Feed, where users can create posts, follow other users, and view a personalized feed containing content published by the people they follow. The system should organize posts in reverse chronological order, displaying the newest content first.
The central challenge is efficiently distributing posts across a massive social graph while maintaining fast feed retrieval. When a user publishes a post, that content should become available in the feeds of their followers. Since different users may have vastly different numbers of followers, the system must accommodate both ordinary accounts and highly popular accounts without compromising feed performance.
Another important challenge is supporting scalable feed generation and pagination. Users should be able to load their feeds quickly and navigate through older posts using pagination. The system must support approximately 2 billion users, with no fixed limit on how many accounts a user can follow or how many followers an account can have.
The platform prioritizes high availability over strict consistency, allowing newly published posts to take up to one minute to appear in followers' feeds. Both creating posts and retrieving feeds should complete within 500 milliseconds, ensuring a responsive experience despite the massive scale of the social graph.
The design focuses on post creation, follow relationships, chronological feed generation, and feed pagination. For simplicity, relationships are modeled as unidirectional follows rather than bidirectional friendships. Likes, comments, private posts, and restricted content visibility are outside the scope. Users are assumed to be authenticated, with their user IDs available through an existing session or JWT.
Post Creation: Users can create and publish posts on the platform. Newly published posts should become available to the author's followers through their news feeds.
User Following: Users can follow other users to receive their posts in a personalized news feed. The system must support unidirectional follow relationships without imposing a fixed limit on the number of accounts a user can follow or the number of followers an account can have.
Chronological News Feed: Users can retrieve a personalized feed containing posts from the accounts they follow. Posts must be displayed in reverse chronological order, with the newest posts appearing first.
Feed Pagination: Users can navigate through their news feeds using pagination, allowing them to retrieve additional pages of older posts beyond the initial feed results.
High Availability: Prioritize availability over strict consistency, ensuring users can continue creating posts and accessing their feeds even when newly published content has not fully propagated.
Eventual Consistency: Allow up to one minute of post staleness. Newly published posts should become visible in followers' feeds within this window.
Low-Latency Post Creation: Complete post creation requests within 500 milliseconds, providing a responsive publishing experience.
Low-Latency Feed Retrieval: Return news feed requests within 500 milliseconds, including requests for additional pages of older posts.
Massive Scalability: Support a social networking platform with approximately 2 billion users, including large-scale post creation, follow relationships, and feed retrieval.
Unbounded Follow Relationships: Support users following an unlimited number of accounts and accounts having an unlimited number of followers, without imposing application-level limits on the size of the social graph.