LESSON 01 · Product contract

Define a useful suggestion

Decide what a prefix may match, who sees the result, and how quickly it must appear.

SYSTEM VIEW

The suggestion path

Diagram view
Requests—
List shows—
Server budget—

Watch “camera” typed into a search box: which keystrokes become requests, which answer stays on screen, and how long each part may take.

  1. Set the contract before choosing an index. The Client sends “cam”, and the Query API returns five popular completed searches that begin with it. Case and accents fold, so “Café” matches “cafe”; spell correction is a separate feature.

    Match
    prefix only
    Results
    5
    Normalize
    Café = cafe

    What changed

    • “cam” sent
    • 5 suggestions back
  2. If every key fired a request, typing “camera” would send six of them, one per letter, from “c” through “camera”. That is the traffic a debounce cuts.

    Typed
    “camera”
    Requests
    6

    What changed

    • 6 requests, one per key
  3. The Client debounces: it waits for a pause in typing before it sends. With an example 100 ms debounce, someone who pauses only after “cam” and “camera” sends two requests instead of six, each tagged with a sequence number.

    Debounce
    100 ms (example)
    Sent
    2 of 6

    What changed

    • 100 ms pause before sending
    • “cam” #1
    • “camera” #2
  4. Replies can arrive out of order. The reply to #1 is slow and lands after the reply to #2. Cancelling #1 can race a request that has already finished, so the Client shows only the newest sequence number: #2 stays, #1 is dropped.

    Shows
    #2, the newest
    Drops
    #1, stale

    What changed

    • #2’s reply lands first
    • #1’s late reply dropped
  5. Target a high percentile from keystroke to visible list, not a server average. In an example budget of 200 ms from the request, an 80 ms mobile round trip and 20 ms of rendering leave the server 100 ms at p99.

    Budget
    200 ms from request
    Network
    80 ms round trip
    Render
    20 ms

    What changed

    • 80 ms on the network
    • 20 ms to render
    • Server gets 100 ms
  6. You may not need any of this. A country picker with 200 fixed entries ships its list with the page and filters it in the browser: no request to debounce, no stale reply to drop, no server budget.

    List
    200 entries
    Filter
    in the browser

    What changed

    • 200 entries in the page
    • No requests to the Query API

Space plays · ← → step · Home resets

THE IDEA

How it works

Autocomplete answers an incomplete input, not a completed search. Set the contract first: prefix-only or substring matches, result count, normalization (folding case and accents so “Café” matches “cafe”), supported languages, regional differences, personalization, and empty-input behavior. A useful first version returns five popular completed searches that begin with the typed prefix. Spell correction is a separate feature with its own index and ranking work.

The client should debounce, meaning it waits for a short pause in typing before sending a request. If every key fired a request, typing “camera” would send six. With an example 100 ms debounce, a person who pauses only after “cam” and “camera” sends two. The client should also ignore late responses for older inputs, because responses can arrive out of order. Cancellation helps but can race with an already completed request, so tag each request with a sequence number and show only the newest.

Define a high-percentile latency target from keystroke to visible suggestions, not just the server average. As an example budget, if a list should appear within 200 ms of the request, an 80 ms mobile round trip and 20 ms of rendering leave the server 100 ms at p99. Very short prefixes can be disproportionately expensive because they cover large candidate sets. You may not need any of this: a country picker with 200 fixed entries can ship its list with the page and filter in the browser.

DECISION POINT

A user types “ca” and then “cat,” but the “ca” response arrives last. Which suggestions should remain visible?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Specify matching, ranking, context, and latency before choosing an index.
  • Debouncing reduces traffic; stale-response handling preserves correctness.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
ApplyQUESTION 01

Which of these belongs in the suggestion contract rather than the implementation?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.