Social News Feed With Live Engagement
Design a chronological media feed with follows, live engagement counters, and bounded search over accounts, post text, hashtags and places that stays usable during viral traffic.
Problem statement
For this exercise, assume a social product serves millions of users. Users can publish text, image, or video posts, load a feed, like posts, and see like and view counters update in near real time. For this exercise, assume a feed contains posts from followed accounts in reverse creation order, feed pages contain at most 50 posts, and posts are retained for seven years. Feed reads should complete within 500 ms at p95 with 99.99% availability; counters may lag by up to two seconds. Post editing and advertising are outside scope. Explain how the design handles ordinary traffic and a suddenly viral creator or post.
For this exercise, also support text search over public account handles/display names and the text of currently published public posts. Search is separate from the followed-account feed; it may find accounts or posts the user does not follow.
A request chooses accounts or posts, contains bounded search text and returns at most 50 matches. Match all normalized query terms; account results use normalized handle then account ID, and post results use reverse creation time then post ID. Explain a stable cursor for that chosen ordering.
Search response p95 targets 500 ms and new public records should normally become searchable within 30 seconds. Return index progress or a degraded indication when freshness cannot be met. Search must not return an unpublished, expired or unavailable post merely because its index entry is stale.
Personalized ranking, direct messages, stories, private-account access and review of media content are outside scope; the exercise’s published searchable posts are public. For this exercise, account handles and display names are immutable after creation; profile editing is outside scope.
Search cursors also bind the index generation. If that generation is no longer available, return an explicit restart/error rather than applying an old cursor to a new generation. New records may require a fresh search; pagination does not freeze the entire changing catalog.
For this exercise, also assume an image post may carry up to 30 hashtags taken from its caption and at most one place chosen from an existing shared place catalog, where a place has a stable place ID and a name; both are fixed when the post is published, like the rest of the post.
Users can follow and unfollow accounts; repeating either request has no further effect, and posts of an unfollowed account stop appearing on later feed reads within 30 seconds. State whether a new follow adds the account's recent posts to the feed.
Search also finds public published image posts by exactly one hashtag or exactly one place ID, newest first (creation time, then post ID), in pages of at most 50, under the same latency, freshness, degraded-result, eligibility and cursor rules as account and post-text search.
Hashtags are matched as exact tags, case-insensitively and without the leading #, not as prefixes. The place catalog and its name lookup are an existing dependency and are not designed here.
Map-area or radius search, trending or popularity ranking, hashtag suggestions, following hashtags, follower lists and counts, and editing hashtags or places after publication are outside scope.
What to build
- A user can publish a text, image, or video post that becomes eligible for followers' feeds; an image post may carry hashtags and one place.
- A user can follow or unfollow an account with a retry-safe request, and later feed reads reflect the current follow relationship within 30 seconds.
- A user can read cursor-paginated feed pages containing posts from followed accounts in reverse creation order. Users can also search public accounts, published public-post text, and public image posts by one hashtag or one place through a separate bounded, cursor-paginated operation.
- A user can like or unlike a post, and a delivered post view can be counted without retry inflation.
- Feed clients can observe like and view counters that converge within the stated freshness window.
At scale
- The product serves millions of users and supports text, image, and video posts.
- For this exercise, assume feed reads complete within 500 ms at p95 with 99.99% availability.
- For this exercise, assume engagement counters may lag authoritative events by at most two seconds.
- For this exercise, assume feed pages contain at most 50 posts and posts are retained for seven years. For this exercise, search pages also contain at most 50 matches, search p95 is 500 ms, and index visibility normally trails publication by at most 30 seconds.
- For this exercise, assume an image post carries at most 30 hashtags and one place, so one publish can create up to 31 search postings, and a single popular hashtag or place may receive about 1% of all new image posts along with many concurrent searches.