Preparing your design workspace

Loading the problem and your latest saved attempt…

Mutual Friend Lookup Service

Design exact pairwise mutual-friend counts and stable member pages while friendship changes, hot users and cached graph views compete with freshness.

Problem statement

For this exercise, assume a signed-in member opens another existing member’s profile and asks which accepted friends they share. The existing relationship authority stores user(userid,name) and relationship(relationship_id,userid1,userid2). Retain both supplied tables.

Accepted friendships are unique undirected pairs without self-edges; either endpoint orientation may be stored. All member profiles and accepted friendships are visible to signed-in members. Design only the mutual-friend lookup service and its handling of committed changes from that authority.

Friend requests, blocks, private accounts, recommendations, feeds and other social-network features are outside scope.

A successful response contains the exact shared-user count and one page of shared IDs and display names from one declared committed snapshot. An empty result means the intersection was completely checked. A dependency timeout must produce an explicit unavailable result rather than a false zero.

Sort members by ascending user ID, return at most 20 per page, and bind an opaque authenticated cursor to the user pair, snapshot and position. Keep a pinned result available for at most two minutes; show its snapshot and coverage time on every page.

A pinned page may be older than the new-lookup freshness target, and an expired cursor requires a fresh lookup. Count, membership and names must refer to the same declared snapshot.

What to build

  1. For two different existing users, return an exact count and a bounded page of accepted friends shared by both, with IDs and names from one committed snapshot.
  2. Continue a successful lookup in stable user-ID order against the same pinned snapshot for up to two minutes; distinguish invalid input, expired continuation and unavailable data from a proved empty result.
  3. Reflect committed friendship changes in fresh lookups using complete, truthfully dated graph coverage; serve no fresh-lookup success when the required coverage cannot be established.

At scale

  • For this exercise, assume 10 million users and 100 million accepted friendship edges, averaging 20 endpoint memberships per user; a few users have 100,000 accepted friends.
  • Assume 10,000 peak pair lookups per second and 1,000 committed friendship changes per second. Repeated hot pairs and high-degree pairs must not exhaust the capacity for ordinary lookups.
  • Target 300 ms p95 for healthy first lookups. At response dispatch, conservative age of the complete snapshot’s truthful coverage time, including a clock margin, must be at most 60 seconds; expose that time and return unavailable when the bound cannot be met. Computing or caching an old view does not advance its coverage.
  • A continuation pins the original snapshot for at most two minutes and exposes its age. Its older snapshot is explicitly allowed for that continuation; starting a new lookup must satisfy the 60-second target again.