Preparing your design workspace

Loading the problem and your latest saved attempt…

Post Author Friend Count Serving

Serve each post author’s friend count from a large changing social graph without per-post adjacency scans or silent projection drift.

Problem statement

A social platform displays an author’s friend count alongside every post by that author. You are given a user-details table and a user-to-friend mapping table, and the solution must work for millions of users.

For this exercise, assume friendships are unique accepted undirected pairs; pending requests do not count, and the count belongs to the post author rather than the viewer. Enrich already authorized feed pages with permitted counts without returning friend identities.

Relationship adds and removes may be concurrent or replayed, and counts must eventually reflect committed changes without double applying a transition. A result carries its age or version; missing, forbidden or over-age information is not a current zero.

Feed ranking, recommendations and full friend-list browsing are outside scope.

What to build

  1. Each visible post can show its author’s accepted friend count, reusing one author result when the page contains repeated authors.
  2. Accepted friendship changes eventually affect both endpoint counts; retries and conflicts do not create duplicate count changes.
  3. Count enrichment exposes a version or as-of time and distinguishes unavailable, forbidden or stale outcomes.
  4. Derived counts can be checked and repaired against committed relationship state while normal changes continue.

At scale

  • For this exercise, assume 10 million users and 20,000 peak feed-page reads/s, with up to 50 posts/page.
  • For this exercise, assume a few authors have 1 million friends and appear repeatedly across viral feed pages.
  • For this exercise, target p95 count enrichment below 300 ms and healthy count age no greater than 60 seconds; authorization is still enforced immediately.
  • For this exercise, relationship mutations and projection events may arrive concurrently or be replayed, and repair must not discard newer accepted changes.