HomeArchitecturesFacebook Social Graph TAO
๐Ÿ—„๏ธ Data & InfrastructureExpertWeek 8

Facebook Social Graph TAO

The Associations & Objects model powering 2B people

Meta/FacebookTwitterLinkedIn

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

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
+1 more steps

How It Works

1

โ‘  Client queries 'friends of user 123'

2

โ‘ก TAO follower cache checked first (read-through)

3

โ‘ข Cache miss escalates to TAO leader

4

โ‘ฃ Leader misses, MySQL shard queried

5

โ‘ค Result cached in leader, propagated to followers asynchronously

6

โ‘ฅ 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

1

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.

2

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.

3

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.

4

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.

5

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.

  1. 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?

  2. Q2

    Explain TAO's two-level cache hierarchy. Why two levels instead of one? What consistency guarantee does this provide?

  3. Q3

    A celebrity with 100M followers posts a photo. How does TAO prevent the thundering herd problem on the cache?

  4. Q4

    How would you handle cross-region consistency in a geographically distributed social graph? What trade-offs would you make?

  5. Q5

    Compare TAO's Objects/Associations model with a property graph database like Neo4j. When would you choose each approach?

Research Papers & Further Reading

2013

TAO: Facebook's Distributed Data Store for the Social Graph

Bronson, N. et al. (Facebook)

Read

Listen to the Podcast Episode

๐ŸŽ™๏ธ Free Podcast

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 Episode

Free ยท No account required ยท Listen in browser

More Data & Infrastructure

View all
๐ŸŽ™๏ธ Podcast ยท All Free

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