CMD Guide
HomeSystem DesignDatabases

RealWorld Examples and Case Studies

Real systems rarely pick one database; they route each access pattern to the store whose data model and consistency guarantees make that pattern cheap, then keep the copies in sync — the win comes from matching the shape of the query to the shape of the index, not from loyalty to SQL or NoSQL. This is polyglot persistence. The famous case studies below are only interesting once you see the mechanism underneath them, so we trace one end to end: how Facebook's TAO answers "who liked this post" for billions of users.

The mechanism: a graph-shaped cache over a relational store

Facebook's social data is a graph — users, posts, comments, likes — and the dominant query is a traversal: give me the edges around this node. A relational schema can store that, but every friend-list or like-count render becomes a join against a table with trillions of rows, and reads outnumber writes by roughly 500:1. TAO ("The Associations and Objects") is the layer that reconciles this: a graph-aware, read-through/write-through cache sitting in front of sharded MySQL, exposing exactly two primitives.

The cache is two-tier and per-region: many follower tiers serve reads from RAM; one leader per region owns writes and cache fills for its shards; and each shard has a single master region that all writes for that shard must funnel through. MySQL is still the durable source of truth — TAO is the access pattern made fast, not a new database.

diagram
diagram

A worked trace: Alice (EU) likes post 42 (US-mastered)

Post 42 lives on shard 7, whose master region is US. Alice is served from EU. Here is the exact data and the two paths.

ConceptTAO representation
Alice, the postObjects user:308, post:42
"Alice likes 42"Association (308, LIKES, 42, t=1719900000)
Inverse, for the counterAssociation (42, LIKED_BY, 308)
"how many likes?"assoc_count(42, LIKED_BY)

Read path — assoc_count(42, LIKED_BY) (99.8% of TAO ops are reads):

  1. EU app asks its local follower. Warm cache → returns 1,204,318 in ~1 ms. Done for the vast majority of requests.
  2. On a miss, the follower forwards to the EU leader.
  3. Leader miss → reads MySQL shard 7 (id1=42, atype=LIKED_BY) from the EU replica, ~10–20 ms.
  4. Leader caches the count and back-fills the follower; the next million reads are ~1 ms again.

Write path — assoc_add(308, LIKES, 42) (the rare 0.2%):

  1. EU leader sees shard 7 is US-mastered, so it forwards the write to the US master leader — a write cannot commit in EU.
  2. US master writes the edge to MySQL, creates the inverse (42, LIKED_BY, 308), bumps the count to 1,204,319.
  3. MySQL replicates US→EU asynchronously; the master also invalidates/refills the follower tiers.
  4. Window of staleness: until replication + invalidation land, an EU follower may still answer 1,204,318. Alice sees her own like immediately only because TAO routes her read-after-write through the path that has the fresh value; a friend in EU may lag by tens of milliseconds. This is eventual consistency across regions, and it is a deliberate trade for read latency.

The other case studies, read as mechanism (not anecdotes)

In every case the reasoning is the same sentence: this access pattern, at this scale, this read/write ratio → this store.

Pitfalls

When to reach for polyglot persistence — and when NOT to

Signals that point here: two or more access patterns whose data models genuinely conflict (transactional OLTP and graph traversal and full-text and time-series analytics); an extreme read:write skew or write volume a single node can't hold; a p99 or dollar cost on one pattern that a general-purpose store can't meet no matter how you index it.

The named alternative: one PostgreSQL. Modern Postgres absorbs many "NoSQL" patterns in-process — JSONB for schemaless docs, pg_trgm/GIN for search, arrays and recursive CTEs for shallow graphs, logical replication for read scale. What you gain by staying single-store: one transactional boundary, cross-domain joins, one backup/failover/monitoring surface, one mental model. What polyglot buys instead: each pattern runs on an engine built for it — at the cost of dual-write/CDC plumbing, eventual consistency between stores, and N operational surfaces to staff.

Decide like this: choose polyglot when a single store's data model actively fights the query at your scale — Facebook cannot traverse the friend graph on joins, Netflix cannot take global writes on a single leader. Prefer one Postgres until a specific, measured access pattern's latency or cost forces a specialized store; adopt the second engine for that pattern only, with a clear system of record. Splitting stores before you have that measurement buys complexity you'll pay for and speed you won't feel.

Takeaways


Re-authored and deepened for this guide. Primary source: Bronson et al., "TAO: Facebook's Distributed Data Store for the Social Graph," USENIX ATC 2013 (objects/associations model, two-tier leader/follower cache over sharded MySQL, ~99.8% read operations, per-shard master regions). Cassandra tunable-consistency and leaderless replication from the Apache Cassandra docs and Lakshman & Malik's original Cassandra paper; polyglot-persistence framing from Martin Fowler and from M. Kleppmann, "Designing Data-Intensive Applications" (O'Reilly, 2017). Latency and count values are illustrative but order-of-magnitude realistic.

🤖 Don't fully get this? Learn it with Claude

Stuck on RealWorld Examples and Case Studies? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **RealWorld Examples and Case Studies** (System Design) and want to truly understand it. Explain RealWorld Examples and Case Studies from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **RealWorld Examples and Case Studies** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **RealWorld Examples and Case Studies** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **RealWorld Examples and Case Studies** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes