Friend Of A Friend

Design the social graph service for a follow based social network: it stores who follows whom, and serves two reads, "mutual connections between me and this profile" and "people you may know".

Requirements

Functional

  • Follow, unfollow, and block an account. A block is bidirectional and hides both accounts from each other everywhere in this service.
  • Given a viewer and a profile, return the mutual connection count plus the top 10 mutuals to render as faces.
  • Given a viewer, return 20 ranked suggestions, each with a reason string such as "3 mutual friends".
  • Suggestions must never include accounts the viewer already follows, has blocked, is blocked by, or has dismissed.

Non-functional

  • p99 under 120 ms server side for mutuals, under 200 ms for suggestions.
  • A follow is read your writes for the follower. Other viewers may see it seconds later.
  • Suggestions may be up to 24 hours stale.
  • 99.95% read availability. A degraded answer (count only, no faces) is better than an error.

Scale

50M registered accounts, 30M DAU. 800M follow edges today, growing about 1M new edges per day. Degree is heavily skewed: median 8, mean 16, p99 around 5,000, and roughly 200 accounts sit above 10M followers. Mutuals get 1.2B calls per day, about 14k QPS average and 45k QPS at peak. Suggestions get 60M calls per day. A mutuals response is about 2 KB, a suggestions response about 6 KB. Edge writes peak near 300 per second.

Out of scope

Feed ranking, notifications, direct messages, account search, and training the ranking model. Assume the edge already authenticated the caller and handed you a trusted viewer id.