In a music-streaming web app's search box, why shouldn't it request suggestions on every keystroke, and what should it wait for instead?
answer
- who pays for abandoned requests
- data, battery, flicker, slower real answer
- a short pause in typing
- a useful length, set per script
- local matches never wait
basics
~20 sMost per-keystroke requests ask about text the user has already typed past: they waste data and battery, flicker unreadable results and delay the answer that matters. Wait for a short pause and a useful minimum length; show local matches at once.
solid answer
~40 sSomeone typing an artist's name presses a dozen keys, and only the last few states matter. Asking after every one costs the phone data and battery, makes the list flicker through results nobody can read, lets abandoned requests share a slow link with the useful one so it arrives later, and multiplies traffic to the suggestion service. So the box waits for a short pause in typing, roughly 150-250 ms is a common starting point to tune, and for enough characters to be useful, usually two in Latin scripts but one where a single character is already a word. Recent searches and the saved library are matched in the tab and shown at once, so waiting never looks like nothing is happening, and only the response for the current text may paint.
go deeper
Recall the costs of per-keystroke requests: wasted data and battery, a flickering list, a slower useful answer and extra load. Then name what to wait for: a short pause and enough characters.
Put rough numbers on it: a delay in the low hundreds of milliseconds, a minimum length per script, and local matches with no delay. Explain why only the response for the current text may paint.
Show you have seen the trade-off on a real phone: delays tuned on office Wi-Fi feel slow on mobile, and a single minimum length fails Japanese and Chinese users. Say how you would measure and tune it.
Frame waiting as a product policy with an owner: what the box promises users on slow networks, which numbers it is tuned against, and who may change them without degrading the experience.
## The product question behind the timing A search box that suggests as you type looks as if it should ask the server after every key. In a **music-streaming web app**, someone looking for the artist "Radio Lanterns" presses fourteen keys. A box that asks after each one sends fourteen requests, and the user only ever wanted the answer to the last few states of the text. The interviewer is not asking which timer to use. The timing mechanism itself, and how waiting for a pause differs from capping the rate, is a separate component-level question. This question is about the product: **who pays for the abandoned requests, and what should the box wait for instead?** ## What one request per keystroke costs | Who pays | What it costs | |---|---| | The user on a phone | mobile data and battery spent on answers nobody reads | | The user's eyes | a list that flickers through results for "r", "ra", "rad" faster than anyone can read them | | The useful answer | abandoned requests share the same slow link, so the response for the real query arrives later | | The suggestion service | many times the traffic of the queries people actually mean | | Correctness | more requests in flight means more chances for an old answer to land after a new one | The last row is why the box needs a **latest-wins** rule: only the response for the text currently in the box may paint. That rule is needed whatever the timing, but fewer requests means fewer races to lose. ## What the box waits for instead 1. **A short pause in typing.** A delay of roughly 150-250 ms after the last keystroke is a common starting point: short enough that a pause feels answered, long enough that keystrokes in the middle of a word do not each fire. The right figure is measured on real users, not guessed. 2. **Enough characters to be useful.** One Latin letter matches a large share of a catalogue of millions, so many products wait for two before asking the server. The rule is set **per script**: in Japanese or Chinese a single character can already be a word, so the minimum there may be one. 3. **Nothing at all for what is already on the device.** Recent searches and the user's saved library are matched inside the tab, far faster than any network call, so they appear on focus and on every keystroke with no delay. An answer already cached for the exact text is shown at once too. ## What the user sees while the box waits Waiting must never look like nothing is happening. - The **local matches** fill the top of the list immediately. - The **last remote results stay visible** until the next ones arrive, instead of being cleared to a spinner. - **"No results"** appears only when the response for the current text says so. - A thin progress cue is enough to show that more is coming. ## Why "the server is fast" does not settle it A fast suggestion service removes one cost, not the others. Data, battery and flicker are paid on the device whatever the server's speed, and on a mobile network the round trip, not the server's own work, is usually the larger share of the wait. A box tuned on office Wi-Fi against a fast server is the one that feels broken on a train. ## Where the trade-off bites - **Too long a delay** feels sluggish: every millisecond of waiting is added to every suggestion, and on a slow link the network has already used most of the user's patience. - **Too short a delay** fires requests mid-word and brings back the flicker and the wasted data. - **Too high a minimum length** hides suggestions from exactly the users who need them: short artist names, and anyone typing a script where one character is a word. - **Input methods** for Japanese or Korean produce half-formed text while a character is being composed; a box that fires on that text searches for the wrong thing. That is a decision of its own, built on the same principle. ## The one-sentence version Ask the server about what the user means, not about every intermediate state of their typing: wait for a short pause and a useful length, answer what you can locally and from cache at once, and paint only the response for the current text.
- Should the box wait before showing the user's recent searches in a music web app?No. Recent searches and the saved library are already in the tab, so matching them costs no network, data or server time. Show recent searches as soon as the box is focused, filter them on every keystroke with no delay, and keep them at the top of the list so the user always sees something useful while the remote suggestions are still pending.
- Why not use one minimum length of three characters for every locale?Because the useful length depends on the script. Three Latin letters still match many artists, but one Japanese kanji or Chinese character can already be a whole word, so a three-character minimum hides suggestions exactly when they would help. Set the minimum per script, and let local matches ignore it entirely.
- Sending every keystroke is fine as long as the suggestion server is fast.
- A longer delay is always safer, so wait a full second after typing stops.
- Clear the list and show a spinner every time a new request goes out.
- Recent searches should wait for the same delay as remote suggestions.
- Three characters is the right minimum length in every language.