Facebook Social Graph TAO
The Associations & Objects model powering 2B people
Key Insight
Social graphs have extremely skewed access patterns the top 1% of objects get 99% of reads, so tiered caching is essential.
Request Journey
How It Works
โ Client queries 'friends of user 123'
โก TAO follower cache checked first (read-through)
โข Cache miss escalates to TAO leader
โฃ Leader misses, MySQL shard queried
โค Result cached in leader, propagated to followers asynchronously
โฅ Future reads served from cache, write invalidates cache with eventual consistency across data centers
โ The Problem
Facebook's social graph contains billionsof objects (users, posts, photos, comments, pages) and trillions of associations (friend-of, likes, tagged-in, authored-by). The access patterns are extremely read-heavy (>99% reads) and severely skewed โ celebrity profiles and viral posts receive millions of reads per second. A traditional relational database cannot handle this read volume, and a generic caching layer (Memcached) lacks the rich query semantics needed for graph traversals like 'friends of friends who liked this post.'
โThe Solution
Facebook built TAO (The Associations and Objects) โ a purpose-built, geographically distributed cache-and-database system optimized for social graph access patterns. TAO models the graph as Objects (nodes with properties) and Associations (typed, directed edges with timestamps). A two-level cache hierarchy (leader + follower caches per region) provides read-after-write consistency within each region and eventual consistency globally. TAO's API is a fixed set of graph operations, eliminating the impedance mismatch of mapping graph queries to SQL.
๐Scale at a Glance
Billions
Objects Stored
Trillions
Associations Stored
>99:1
Read/Write Ratio
>96%
Cache Hit Rate
๐ฌDeep Dive
Objects and Associations โ The Data Model
TAO models the social graph with two primitives: Objects and Associations. An Object has an id, type, and key-value properties โ a user object has (name, profile_pic_url, join_date). An Association is a typed, directed edge between two objects with a timestamp and optional data โ (user_123, LIKES, post_456, timestamp=...). Associations are stored in association lists sorted by timestamp, enabling efficient queries like 'get the 20 most recent likes on this post.' This fixed data model is deliberately restrictive โ by limiting the API to a small set of operations, TAO can optimize aggressively for those specific access patterns.
Two-Level Cache Hierarchy
TAO uses a two-level caching architecture within each geographic region. Follower caches handle the majority of read traffic and are scaled horizontally โ adding more follower cache servers linearly increases read throughput. Follower caches forward cache misses and all writes to the leader cache, which is the single source of truth for that region's cache state. The leader cache communicates with the underlying MySQL database for persistent storage. This hierarchy provides read-after-write consistency within a region: a write updates the leader, which invalidates the relevant follower caches synchronously. Users see their own writes immediately.
Shard Assignment and MySQL Backend
TAO's persistent storage layer is a massively sharded MySQL deployment. Objects and associations are assigned to shards by object ID using a consistent mapping. Each shard is a MySQL database containing the objects and outgoing associations for its assigned IDs. Association lists are stored in MySQL tables with efficient indexes for the common 'get most recent K associations of type T for object X' query pattern. The MySQL layer handles durability, point-in-time recovery, and schema migrations โ while TAO's cache layer absorbs the read volume that would otherwise overwhelm MySQL.
Cross-Region Consistency โ Eventual with Guarantees
Facebook operates multiple datacenter regions globally. Each region has its own TAO leader and follower caches, and its own MySQL replica. Writes in a region update the local leader and are asynchronously replicated to other regions via MySQL replication. This means cross-region consistency is eventual โ a user in Europe might not immediately see a post written by a user in the US. However, TAO provides read-after-write consistency within a region: a user always sees their own recent writes. For critical operations (like accepting a friend request), the write is sent to the primary region to ensure global ordering.
Thundering Herd Protection
When a celebrity posts and millions of users simultaneously request the same object, a cache miss on a single follower cache could cascade into millions of requests hitting the leader and MySQL. TAO implements thundering herd protection: when a follower cache misses on a key, it marks that key as 'pending' and holds subsequent requests for the same key in a queue. Only one request is forwarded to the leader. When the response arrives, all queued requests are served from the newly cached value. This collapse of concurrent requests is critical for objects with extreme read fanout โ without it, a single viral post could overwhelm the storage layer.
โฌกArchitecture Diagram
Facebook Social Graph TAO โ simplified architecture overview
โฆCore Concepts
Graph Data Model
Objects & Associations
TAO Cache
Eventual Consistency
Shard Assignment
MySQL + Memcached
โTradeoffs & Design Decisions
Every architectural decision is a tradeoff. Here's what you gain and what you give up.
โ Strengths
- โPurpose-built graph API eliminates SQL impedance mismatch for social graph queries
- โTwo-level cache hierarchy achieves >96% cache hit rate on extremely skewed access patterns
- โRead-after-write consistency within each region ensures users always see their own writes
- โThundering herd protection prevents cache miss cascades for viral content
โ Weaknesses
- โEventual consistency across regions means users can see stale data from other regions
- โFixed data model (Objects + Associations) cannot express arbitrary graph queries efficiently
- โMySQL backend limits the types of efficient queries to pre-defined access patterns
- โCross-region write coordination for critical operations adds latency to those specific paths
๐ฏFAANG Interview Questions
Interview Prep๐ก These questions appear in FAANG system design rounds. Focus on tradeoffs, not just what the system does.
These are real system design interview questions asked at Google, Meta, Amazon, Apple, Netflix, and Microsoft. Study the architecture above before attempting.
- Q1
Design a social graph storage system for 2B users. What data model would you use and how would you handle the read/write ratio?
- Q2
Explain TAO's two-level cache hierarchy. Why two levels instead of one? What consistency guarantee does this provide?
- Q3
A celebrity with 100M followers posts a photo. How does TAO prevent the thundering herd problem on the cache?
- Q4
How would you handle cross-region consistency in a geographically distributed social graph? What trade-offs would you make?
- Q5
Compare TAO's Objects/Associations model with a property graph database like Neo4j. When would you choose each approach?
Research Papers & Further Reading
TAO: Facebook's Distributed Data Store for the Social Graph
Bronson, N. et al. (Facebook)
Listen to the Podcast Episode
Alex & Sam break it down
Listen to a conversational deep-dive on this architecture โ real trade-offs, production context, and student-friendly explanations. Free, no login required.
Listen to EpisodeFree ยท No account required ยท Listen in browser
More Data & Infrastructure
View allSpotify Music Recommendation System
Collaborative filtering, Discover Weekly, and the AudioEmbeddings pipeline
Spotify ยท Apple Music ยท YouTube Music
GitHub Pull Request & CI/CD Pipeline
Git internals, check suites, and the webhook fanout that powers DevOps
GitHub ยท GitLab ยท Bitbucket
LinkedIn Feed Ranking Architecture
Heavyweight ML scoring with online/offline feature pipelines
LinkedIn ยท Facebook ยท Twitter
Listen to more architecture deep-dives
30 free podcast episodes โ Alex & Sam break down every architecture in this library. Listen in your browser, no account needed.
All architecture articles are free ยท No account needed