MentorNode
Start free
Social, Feed & EngagementMediumdesign-social-graph

Design a Social Graph / Follow Service

Design storage and query for follows, friends, and blocks: bidirectional lookups, friends-of-friends traversal, and accounts with a hundred million edges.

Adjacency ListsGraph PartitioningBidirectional IndexesDenormalization
Traffic & Capacity Estimates:

2B users · 200B edges · 500k edge writes/second · friends-of-friends in <100ms

Functional Requirements

  • •Create and remove directed edges (follow, block, mute) and query both directions.
  • •Return follower and following lists with stable pagination.
  • •Answer 'do these two users have a relationship' in a single hop.
  • •Support second-degree queries (mutual friends, friends-of-friends) for recommendations.

Non-Functional Requirements

  • •Edge existence check under 5ms at p99 — it is on the permission path for every view.
  • •An account with 100M followers must not break the storage model for everyone else.
  • •Blocks must apply immediately and must never be eventually consistent in the permissive direction.

Back-of-the-Envelope Math

  • 200B edges * 40 bytes = 8 TB of raw edge data, doubled for the reverse index.
  • Friends-of-friends for a user with 1,000 friends who each have 1,000 friends touches 1M edges — it must be precomputed or sampled.

Key Architectural Trade-offs

  • A dedicated graph database (natural traversals, harder to shard at this scale) vs sharded adjacency lists in a key-value store (scales trivially, multi-hop queries become application code).
  • Storing both directions of every edge doubles writes and storage, and is what makes 'who follows me' a single read instead of a full scan.
  • Safety-critical edges (blocks) demand strong consistency; ordinary follows tolerate eventual consistency — mixing the two in one store means the strict path sets the cost.

Click or drag a component onto the canvas, then connect the handles to draw the data flow.

3 nodes · 2 edges

Components · 35

Client & Edge4
Compute & Gateway7
Storage & Caching11
Messaging & Streaming6
Coordination & Ops5
Intelligence2
Canvas overview