Blog 10 — Meta: Designing the Social Graph
C
Qubits of DPK
March 21, 2026
Core Case Studies
Core Concept: Graph DB vs relational DB, TAO distributed cache, Eventual consistency in social networks
Why SDE-2 Critical: Social feed design is the most commonly asked system design question
Status: Draft notes ready
Quick Revision
- Problem: Social graph reads are simple but happen at enormous scale.
- Core pattern: MySQL shards as source of truth with TAO-style caching on top.
- Interview one-liner: Optimize for actual query shape; most social graph reads are 1-hop, not deep traversal.
️ Architecture Overview
javascript
QUBITS OF DPK
Core Concepts
Why Not a Traditional Graph Database?
javascript
QUBITS OF DPK
TAO — The Associations and Objects Cache
javascript
QUBITS OF DPK
Social Graph Sharding
javascript
QUBITS OF DPK
Eventual Consistency in Social Graphs
javascript
QUBITS OF DPK
Scale Achieved
5 Interview Questions This Blog Unlocks
Q1. Design Facebook friends / Instagram followers
Answer: Store relationships as edges in a table (user_id, friend_id, created_at). For follower counts, maintain a counter table. Cache hot social graphs in TAO-like system (Redis). Shard by user_id. Celebrities get separate shards. Use eventual consistency for social data.
Q2. Why did Facebook use MySQL instead of a graph database?
Answer: Facebook's queries are mostly 1-hop ("get all friends of user X"). Graph databases excel at multi-hop traversals. For 1-hop at 3B user scale, MySQL + smart indexing + TAO cache is faster, more operationally mature, and easier to scale than Neo4j.
Q3. What is TAO and what problem does it solve?
Answer: TAO is Facebook's distributed cache for the social graph. Without it, every social graph query would hit MySQL directly — impossible at billions of QPS. TAO caches objects and associations in a read-through manner, serving 99%+ reads from memory with MySQL as backing store.
Q4. How would you design a "People You May Know" feature?
Answer: Friends-of-friends algorithm: for user A, get all friends, then for each friend get their friends, count overlap. Store result in precomputed table (updated async). Use Bloom filters to exclude existing connections. Cache results with 1-hour TTL. This is a batch job, not real-time.
Q5. How does Facebook handle celebrities with 100M followers differently?
Answer: Regular users: edges stored in standard shards. Celebrities: edges get dedicated shards + aggressive edge caching. Fan-out on read (compute feed at read time) instead of fan-out on write (pre-compute for 100M followers on every post). Hybrid approach based on follower count threshold.