Typeahead
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 suggestion requests a second at the evening peak?

      How many of those requests reach the suggest servers?

        Can every server hold the whole index in RAM?

          How many suggest servers, and how much RAM each?

            Build-up · 6 steps

            Build the high-level design

            One functional requirement at a time, ending with a design that works end to end at modest scale.

            Step 1 of 6

            Top completions as you type

            The servers do no searching at request time. Each holds the whole index in RAM with the top 10 stored per prefix, so answering “iph” is a lookup, with no database on the path.

            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

              “Every keystroke asks for the ten most popular queries starting with a prefix, 117k times a second. What structure answers it?”

              Your move. Pick an approach:

            2. Deep dive 2 of 6

              Interviewer

              “Every search shifts what’s popular, 35k times a second at peak. How does the index keep up?”

              Your move. Pick an approach:

            3. Deep dive 4 of 6

              Interviewer

              “A phone launch makes everything under “i” hot for a week. How do you spread the 15 GB index across servers?”

              Your move. Pick an approach:

            4. Deep dive 5 of 6

              Interviewer

              “Product wants your recent searches and your city to shape the list. Where does that happen?”

              Your move. Pick an approach:

            5. Deep dive 6 of 6

              Interviewer

              “A court orders one suggestion removed, and offensive phrases must never appear. Where do you filter?”

              Your move. Pick an approach:

            Build-up · 8 steps

            Follow one keystroke, then one search

            The read path is the app, the CDN and the suggest servers. Everything that learns, counts or filters runs beside it and arrives ahead of time.

            Step 1 of 8

            Type

            After a 100 ms pause the app sends GET /v1/suggest?q=iph&lang=en&region=IN-MH, unless its own cache or a complete list already has the answer.