Katkat

Design a Ranked Social Feed with Hybrid Fan-Out

LinkedInSoftware Engineer · Onsite

Last updated

Design a scalable, read-heavy ranked social feed supporting millions of users. The system must balance fan-out-on-write and fan-out-on-read while ensuring read-your-own-writes consistency for authors.

Scenario

Design the feed generation and delivery architecture for a professional social network similar to LinkedIn. Users can create posts, follow other members, and view a personalized, ranked feed of content from their network.

A key requirement is read-your-own-writes consistency: authors must immediately see their own newly published posts in their feed. The system must also gracefully handle "hot keys" (celebrities or company pages with tens of millions of followers) without introducing write amplification or fan-out storms.

Requirements

Functional Requirements

  • Post Creation: Users can publish text and media-link updates.
  • Follow Graph: Users can follow and unfollow other users or pages.
  • Feed Retrieval: Users can fetch a ranked, paginated timeline of relevant updates from followed entities.
  • Immediate Author Visibility: An author's newly published post must appear at the top of their personal feed immediately after creation.

Non-Functional Requirements

  • Latency: p99 feed load latency under 200 ms.
  • Availability: 99.99% availability for the read path; eventual consistency is acceptable for follower feed delivery.
  • Freshness: Non-author followers should see new posts within 5 seconds under normal conditions.

Scale Assumptions

  • 300 million Daily Active Users (DAU).
  • 30 million posts created per day (~350 posts/sec average, 1,500/sec peak).
  • Feed requests: 3 billion requests per day (~35,000 queries/sec average, 70,000/sec peak).
  • Average follower count is 500, but top creators/influencers have over 10 million followers.

Key Architectural Topics to Address

  1. Hybrid Fan-Out Strategy: Explain when to push (fan-out on write) versus when to pull (fan-out on read), and how the two paths merge when constructing a user's feed.
  2. Read-Your-Own-Writes: Design the mechanism ensuring an author's post appears instantly on their client without waiting for asynchronous follower fan-out.
  3. Inbox Caching & Bounding: Define the schema and eviction policies for user timeline inboxes (e.g., capped at 800 post IDs in Redis).
  4. Feed Ranking & Hydration: Outline how candidate post IDs are scored, ranked, and hydrated with user profile and media metadata.
  5. Pagination & Consistency: Choose an appropriate pagination mechanism (e.g., cursor-based vs. offset) resilient to new post insertions.
  6. Fault Tolerance & Recovery: Describe retry semantics with dead-letter queues (DLQs) and recovery strategies if timeline caches are lost.

Hints

Hint 1

Differentiate regular accounts from high-follower accounts to avoid fan-out write amplification, combining pre-computed feed caches with dynamic read-time queries for influencers.

Hint 2

Inject newly authored posts directly into the author's own timeline cache synchronously during post creation to guarantee immediate self-visibility.

Hint 3

Use stable cursor-based pagination using a tuple of score and post ID rather than offset-based paging to avoid duplicate or skipped posts as feeds shift.

Follow-up questions

  • How would you handle feed updates when a user unfollows a prolific creator or when a post is soft-deleted by an author or content moderator?
  • If the machine learning ranking service experiences high latency or an outage, how should the feed service degrade gracefully?
  • How would you rebuild the bounded feed caches for active users following a catastrophic multi-region Redis outage without overwhelming the primary database?