System Design

Social Graph

Design the follow graph service for a social network like Twitter or Instagram.

Functional requirements

  • A user can follow or unfollow another user; follows are directed, and following a private account creates a pending request that becomes an edge once approved.
  • List a user's followers and following, paginated newest first, with totals on the profile; the feed service can also stream a whole follower set (e.g., 100M IDs).
  • Answer relationship checks in bulk: for a viewer and 50 listed users, does the viewer follow each and does each follow the viewer (e.g., to render Follows you).
  • Compute mutual follows between two users (e.g., 'Followed by alice and 12 others you follow') and friends-of-friends candidates, both capped in size.
  • Users can block someone, removing any edge in both directions and preventing new ones; private accounts show their lists only to approved followers.

Non-functional requirements

  • Relationship checks and the first list page are on the profile-render path: p99 under 50ms for a bulk check of 50 users and under 100ms for a list page.
  • Consistency: a follow is read-your-writes for the actor (they immediately see Following), both directions converge within 5 seconds, and follower counts may be a few seconds stale; a block must never leave an edge alive in either direction.
  • Durability: an acknowledged follow, unfollow, or block is never lost; the graph is the feed's source of truth, and silently lost edges change what people see.
  • Availability: list reads and relationship checks stay available during a partition even if slightly stale; writes may be delayed but never silently dropped.
  • Privacy and abuse: private and blocked relationships are enforced server-side on every read; follows per account are capped (e.g., 400 per day) to slow follow-spam.

Scaling & constraints

  • 1B users and ~300B directed follow edges, growing ~15% per year; the median user has 200 followers and follows 300.
  • The top 10,000 accounts each have over 10M followers and the largest ~150M; one celebrity's follower list alone is ~1.2GB of 8-byte IDs.
  • Writes: ~20,000 follow/unfollow operations per second on average, peaking at 100,000 per second; a single account can gain 1M followers in an hour.
  • Reads: ~5M bulk relationship checks per second (~50 IDs each) and ~500,000 list-page reads per second; read:write ratio is roughly 300:1.
  • Each edge with metadata (follower_id, followee_id, created_at, state) is ~40 bytes, so ~12TB raw per direction before replication and indexes.
  • Blocks are ~0.5% of edges and private accounts ~20% of users; the feed service streams a full follower set ~50,000 times per day for accounts with over 1M followers.

Out of scope

  • News feed fan-out and timeline storage (the feed service consumes the graph).
  • Ranking and machine learning for people-you-may-know beyond candidate generation.
  • Account creation, authentication, and profile data.
  • Spam and fake-account detection beyond per-account follow rate caps.

Sign in to save your progress

AI design evaluation

Get a score, what your board does well, what to fix first, and what an interviewer would ask next.

Sign in to evaluate

Sign in to get AI feedback on your design.