# How to design a social graph service

Source: https://systemdesignsim.com/system-design/social-graph

System design · Typed edges, privacy and high-degree accounts

A social graph stores entities and typed relationships. It is not the news feed itself. Start with product queries, then choose adjacency indexes and consistency boundaries. Blocks, privacy and deletion apply on every read path.

Updated October 28, 2026 · 4 min read

[Take the news feed challenge](https://systemdesignsim.com/challenges/news-feed)

![Social Graph Service architecture diagram](https://systemdesignsim.com/diagrams/social-graph-system-design-diagram.svg)

A relationship API updates adjacency storage and publishes changes for suggestions.

## The short version

* A social graph stores entities and typed relationships. It is not the news feed; ranking and delivery are separate problems.
* State the product queries first: outgoing adjacency, reverse followers, mutual friends, degree counts.
* Celebrities are hot nodes. Plan from degree percentiles, not the mean.
* Counters and suggestions may lag. A block must not.
* Version or tombstone edges so a delayed event can't resurrect a deleted follow.

## Clarifying questions to ask first

* Are relationships directed follows, mutual friendships, blocks or several typed edges? (Assume typed directed edges.)
* Which queries must be fast? (Assume paged connection lists and mutual-friend checks; suggestions are asynchronous.)
* Which privacy and block rules apply on each read? (Assume a block takes effect within a stated freshness target, even if caches are stale.)
* How large can one user's degree get, and how fresh must suggestions be after a follow, block or deletion?

## Numbers that shape the design

Assumptions, not measurements of a real network. Ten million users averaging 300 outgoing relationships make 3 billion directed edges. At an illustrative 100 bytes per edge and index, that's about 300 GB before replication and backups. One million daily users making 20 reads a day is about 231 reads/s, or 2,310/s at an assumed ten-times peak.

A celebrity with 50 million followers can be far hotter than average. A reverse index adds storage and write work, and a mutual-friend query may inspect many neighbours, so bound it or precompute candidates.

## API

```
PUT /users/{actor}/relationships/{target}
{ type, idempotencyKey }
200 { relationship, version }

DELETE /users/{actor}/relationships/{target}?type=follow
204

GET /users/{id}/following?cursor=...
200 { items, nextCursor, graphVersion }
```

A repeated follow returns the existing state. Delete writes a version or tombstone so a delayed event can't recreate the edge. Stable cursors page large lists without loading every edge, and the service checks the caller may see the relationships it returns.

## Data model

A relationship is a typed directed edge \`(sourceId, edgeType, destinationId, createdAt, state, version)\`, unique on source, type and destination so a follow can't duplicate. If reverse lookups are common, index by destination and type. Degree counters are derived: expose their lag and make them rebuildable. Don't copy private profile data into edges, where it goes stale after a privacy change.

## High-level design

A relationship API authenticates and checks policy, a partitioned adjacency store persists the edge, and a change log publishes it. A versioned cache serves common pages. Separate consumers update counters, suggestion candidates and feed projections, outside the write transaction.

Partitioning by source makes outgoing adjacency direct, but a high-degree source gets hot. A destination index serves reverse reads at extra write cost. Bucketing hot adjacency spreads load but makes readers merge buckets. Measure before adding complexity.

## Caching, privacy and deletion

Cache adjacency pages with a version or short expiry. A block invalidates relationship views, and authorisation always consults current policy, because delayed invalidation can reveal a relationship meant to be hidden. Filter already-followed, blocked, suspended and private candidates out of every suggestion response.

On deletion, mark the account unavailable first, then remove edges and derived data asynchronously, tracking completion across every index and projection. Alert on the oldest unapplied privacy event separately from analytics lag.

## Friend suggestions

A background job generates candidates from shared connections or other approved signals, scores them and applies eligibility and privacy filters. Diversity stops every result coming from one group. The request path returns a bounded list instead of traversing the graph. New users have few edges, so a product may use declared interests, each signal with its own consent and abuse controls. Don't silently upload address books. Let users dismiss suggestions.

The USENIX TAO paper (2013) describes Facebook's graph store and a fixed set of graph queries. It supports the lesson that query shape matters, not any claim about Facebook's current architecture.

## Common traps

* Choosing a graph database before stating the product queries. It doesn't solve hot keys, privacy or fan-out by itself.
* Assuming arbitrary multi-hop traversals, or mutual-friend queries across shards, are cheap.
* Using mean degree alone and missing hot nodes.
* Trusting cached visibility after a block.
* Ignoring versions, so an old create event arriving after a delete resurrects the edge.
* Recomputing all suggestions synchronously on every follow.

## Follow-up questions interviewers ask

* How does a block become visible on every read path?
* How do you handle a user with tens of millions of followers?
* How can users export or delete their graph?
* Which suggestions are online and which are precomputed? (The [Twitter timeline](https://systemdesignsim.com/system-design/twitter-timeline) is a graph consumer; see [caching strategies](https://systemdesignsim.com/system-design/caching-strategies) for freshness.)

## Frequently asked questions

### How are mutual relationships represented?+

Use two directed edges or one undirected relationship with indexed endpoints. Choose based on write atomicity and query needs, then keep the API contract consistent.

### Why keep a reverse index?+

It makes inbound queries efficient but adds write and storage work. Add it when reverse reads justify the cost.

### What is a hot node?+

A node whose adjacency receives far more reads or writes than average. Celebrity accounts are one example in a hypothetical service.

### How can a cache respect blocks?+

Check current visibility separately from cached adjacency, and make block events invalidate or version affected views.

## More system design guides

[All 76 guides](https://systemdesignsim.com/system-design)

* [Caching Strategies explainedCache-aside, write-through, stampedes](https://systemdesignsim.com/system-design/caching-strategies)
* [Design a Twitter TimelineFan-out and the celebrity problem](https://systemdesignsim.com/system-design/twitter-timeline)
* [Design a Maps ETA and Routing Service](https://systemdesignsim.com/system-design/maps-eta)
* [Design a Pastebin](https://systemdesignsim.com/system-design/pastebin)
* [Design a Chat SystemQueues, write scaling, delivery lag](https://systemdesignsim.com/system-design/chat-system)
* [Design an Ad Click AggregatorStreams, Flink windows, exact counts](https://systemdesignsim.com/system-design/ad-click-aggregator)

## Now fix it yourself.

Run the design under real traffic and see what breaks first. No signup.

[Take the news feed challenge](https://systemdesignsim.com/challenges/news-feed)
