Twitter
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    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 tweets a second, and how big is the spike?

      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.

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

            2. 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:

            3. 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:

            4. 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:

            5. 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.