Layer 3 · Go deeper · 11 min
Go deeper
Size it, build it, then make the calls an interviewer will push you on.
Back of the envelope
Size it up
Tap through each step of the arithmetic.
How many home-timeline reads a second at peak?
How many timeline inserts a second does fan-out cost?
How much memory do the cached home timelines need?
Build-up · 6 steps
Build the high-level design
One functional requirement at a time, ending with a working Twitter before any of its extremes arrive.
Step 1 of 6
Post a tweet
The tweet service gets an ID, writes the tweet once, publishes tweet.created and returns the ID straight away. Likes are edges plus a per-tweet count, written by an engagement service.
6 interview moments
You’re the candidate
The interviewer pushes on the hard parts. Pick an approach and see how it holds up.
Deep dive 1 of 6
Interviewer
“Most accounts have a few hundred followers; the biggest have about 100M. How do you build everyone’s home timeline?”
Your move. Pick an approach:
Deep dive 2 of 6
Interviewer
“Up to 143k tweets a second, and each ID is the storage key, the timeline order and the API cursor. How do you mint them?”
Your move. Pick an approach:
Deep dive 3 of 6
Interviewer
“During a match, thousands of tweets a second must be searchable within 10 seconds while queries hit the same index. How?”
Your move. Pick an approach:
Deep dive 4 of 6
Interviewer
“About 1.5B term mentions a day, most of them one-off words and typos. How do you count them to find trends?”
Your move. Pick an approach:
Deep dive 5 of 6
Interviewer
“A TV moment brings 143,199 tweets in one second, 25× normal. How do you make sure posting is never blocked?”
Your move. Pick an approach:
Deep dive 6 of 6
Interviewer
“A cricketer’s tweet after a World Cup win collects thousands of likes a second. How do you keep its like count?”
Your move. Pick an approach:
Build-up · 8 steps
Follow one tweet, then one timeline read
Posting ends when the tweet is stored. Everything else consumes one stream, and each feature reads only its own store.
Step 1 of 8
Post
The client calls POST /2/tweets through the gateway, which authenticates and rate-limits, and reaches the tweet service.