The Tweet Store: How Twitter Stores Tweet Content (T-bird)
Every layer in this guide — the timeline ZSET, Earlybird, the ranking pipeline — ultimately holds a pointer (a tweet ID). Something has to hold the actual freight: the text, the author, the media refs, the timestamp. That's T-bird, the durable tweet store. Understanding its shape explains why "store IDs, not bodies" (see Timeline Service) is even possible, and where the other hot spot in this whole system lives — not the timeline cache, but the tweet itself.
The intuition first
If the timeline service is a wall of mailboxes holding claim tickets, T-bird is the warehouse those tickets point into. There is exactly one copy of each tweet in the warehouse, no matter how many millions of mailboxes hold a ticket for it. That single-copy property is the whole reason edits/deletes and storage costs stay sane at Twitter's scale (the Timeline Service part’s "single source of truth" argument) — but it also means the warehouse shelf holding a viral tweet gets hammered by lookups, which is a different scaling problem than anything the timeline service has to solve.
What T-bird is
Historically: sharded MySQL, fronted by Gizzard — a general-purpose sharding/replication framework Twitter built in-house (the same framework that underlies FlockDB, below). Gizzard sits between the application and a fleet of physical MySQL instances and answers one question for every request: which physical shard(s) hold this row, and which replicas of that shard are healthy right now? The application never talks to a specific MySQL box directly.
application ──► Gizzard (shard router) ──► physical MySQL shard 1 (+ replicas)
├──► physical MySQL shard 2 (+ replicas)
└──► physical MySQL shard N (+ replicas)
The schema, roughly
A tweet row is small and simple — this is a narrow, high-throughput table, not a rich document store:
tweets
──────
tweet_id BIGINT PK (Snowflake ID — Section 6)
author_id BIGINT (who posted it)
text VARCHAR (≤280 chars)
media_ids [...] (pointers to a separate media/blob store, not inline)
created_at derived from tweet_id itself (Snowflake embeds the timestamp)
... (reply-to id, retweet-of id, visibility flags, etc.)
Two things worth noticing: media is not stored inline (images/video live in a separate blob store, referenced by ID — keeping this table narrow and fast), and you don't even need a separate created_at column if you don't want one, because the Snowflake ID is a timestamp (see eventual consistency). Narrow rows mean more rows per page, more rows per cache line, cheaper indexes.
Sharding strategy: by tweet ID, not by author
This is the detail that trips people up, because it's the opposite choice from the social graph (below), and the difference is deliberate:
| Store | Sharded by | Why |
|---|---|---|
| T-bird (tweets) | tweet_id (Snowflake) |
Spreads write load evenly — new tweets get new, monotonically-larger IDs, which round-robin/range-partition cleanly across shards regardless of which author is tweeting. |
| FlockDB (graph) | source_user_id / destination_user_id |
Optimizes for the query shape — "all edges for user X" needs to be a single-shard scan. |
If T-bird sharded by author_id instead, a single hyperactive or viral account would concentrate its write (and read) load onto one shard — the same hot-shard problem the write amplification part solves for fan-out, reappearing on the storage layer. Sharding by tweet ID instead means no single author can create a write hotspot: their tweets are scattered across the shard space by ID, just like everyone else's. The trade-off is that "give me all of user X's tweets" (their profile timeline) is no longer a single-shard scan — but that's a rare, less latency-critical read compared to the constant stream of individual GET tweet:{id} hydration calls (see Timeline Service), so it's the right thing to optimize away from.
Replication: durability and read scaling
Each logical shard is really multiple physical copies (a primary plus replicas), and Gizzard is what makes the application indifferent to which copy answers a request:
- Durability — a tweet write (the async fan-out part, Phase 1b) is acknowledged once it's safely on a primary (and typically at least one replica); losing a single MySQL box doesn't lose tweets.
- Read scaling — read traffic (hydration calls from every timeline render) is spread across replicas, not just the primary.
- Transparent failover / resharding — Gizzard tracks shard-to-host mappings as data, so migrating a shard to new hardware or promoting a replica doesn't require an application change or downtime. This is the same job a service mesh or connection router does elsewhere, purpose-built for MySQL shards.
The tweet cache: absorbing the other read amplification
The Timeline Service part already introduced the idea that a timeline read hydrates IDs into bodies via a tweet cache (GET tweet:{id}). It's worth naming explicitly why that cache is load-bearing, not optional: a single popular tweet is read far more often than it's written. One write; then, over the life of that tweet, one hydration call for every timeline it landed in, every time each of those viewers scrolls past it. For a celebrity tweet fanned out (or pulled) to millions of viewers, that's millions of GET tweet:{id} calls hitting the same row — a classic hot-key problem, structurally identical to the hot-shard problem the write amplification part solves for fan-out, just one layer further down the stack:
1 tweet written to T-bird
│
▼
millions of timeline entries point at it (Sections 2/4)
│
▼
millions of hydration reads for the SAME tweet_id ◄── hot key
This is solved the standard way a hot key is solved anywhere: a cache in front of MySQL (the tweet:{id} cache from the Timeline Service part’s diagrams) absorbs the vast majority of reads, so T-bird itself only sees a trickle of cache-miss traffic per tweet rather than millions of direct hits. For the very hottest tweets, this can mean multiple cache replicas of the same key (so no single cache node becomes the new hot spot) — the same "don't let one node absorb all the traffic" principle the write amplification part applied to fan-out, now applied one layer down to a single row.
Deletes and edits stay cheap — because there's one copy
This is the payoff the Timeline Service part promised: because a tweet exists in exactly one row in T-bird, a delete or edit is one write, not a hunt across millions of timeline copies:
delete tweet T:
1. mark/remove the row in T-bird (one write — the source of truth)
2. tombstone the tweet cache entry for T (so hydration stops returning it)
3. do NOT touch any home_timeline ZSET (they still hold the ID — see below)
Every timeline ZSET that still holds T's ID is now pointing at a tombstone. That's fine and deliberate: the ID is cheap (8 bytes, the Timeline Service part), so instead of proactively scrubbing T out of every follower's ZSET (an unbounded fan-out just to process a delete), the read path simply skips IDs that fail to hydrate at render time. The delete is O(1) at write time; the cost of "cleaning up" is paid lazily, a few bytes at a time, only by viewers who happen to scroll past the tombstoned ID.
Why not one giant MySQL instance
The standard sharding argument, concretely sized for this table:
- Throughput — thousands of tweet writes/sec sustained, tens of thousands at peak (see why timelines are hard), plus the hydration read volume (every timeline render reads ~tens of rows) — orders of magnitude beyond one box's I/O.
- Storage — hundreds of millions of tweets/day accumulating indefinitely; no single disk (or even single machine's attached storage) holds the corpus.
- Blast radius — one giant instance is a single point of failure for all tweet content simultaneously; sharded + replicated means a failure only affects the tweets on that shard, and only until a replica takes over.
The tweet store at a glance
POST /tweet ──► mint Snowflake ID ──► Gizzard routes by tweet_id ──► primary MySQL shard (+ replicas)
│
(durable; Section 7 Phase 1b)
GET tweet:{id} (hydration, Section 5) ──► tweet cache ──miss──► Gizzard ──► replica MySQL shard
▲
absorbs the hot-key
read amplification of
viral/celebrity tweets
T-bird and FlockDB share the same underlying idea (Gizzard-routed, sharded, replicated MySQL) but shard on opposite keys for opposite reasons — tweets shard by ID to spread write load evenly across an unpredictable stream of authors; the graph shards by user ID to keep each user's edge list a single-shard scan. Same tool, tuned to two different access patterns.