skip to content

For a music-streaming web app's search box on mobile networks, how would you budget delay, minimum length and round trip, and which response may paint?

level: middleimportance: must knowfreq 66%

answer

  1. pause-to-paint is a sum
  2. the delay is pure waiting
  3. warm the connection on focus
  4. cache hits skip the delay
  5. paint only the current text's answer

basics

~20 s

Budget pause-to-paint as delay plus round trip plus server plus render, keeping the short delay as the only pure wait. Warm the connection, keep responses small, skip the delay on cache hits, and paint only the response for the current text.

solid answer

~50 s

I budget the time from the user's pause to suggestions on screen: typing delay, connection set-up, round trip, the server's share and rendering. On mobile the round trip dominates, so the delay stays short, around 150-200 ms to start, because it is added to every suggestion. I cut the rest: open the connection when the box gains focus, return a few compact results per group, and answer exact repeats from the cache with no delay. Remote queries start at two Latin characters or one CJK character; below that only local matches show. For painting, each request is tagged with its normalised text, every response goes into the cache, and only the one matching the current input may paint; an older answer never replaces a newer list. While the next answer is in flight, the last list stays up, filtered to the current text, with a quiet progress cue.

code

pseudocode · 13 lines
pseudocode
on input(text):
  q = normalise(text)
  showLocalMatches(q)                 -- recent searches, library: no delay
  if cache.has(q):
    paint(q, cache.get(q)); return    -- exact hit: no delay, no request
  if length(q) < minLength(script(q)): return
  restartTimer(DELAY_MS, () => request(q))

on response(q, results):
  cache.put(q, results)
  if q == normalise(input.value):
    paint(q, results)
  -- otherwise: cached for later, never painted

go deeper

for a junior

Remember that the user waits for the delay plus the network plus the server, and that only the answer for the text in the box should be shown.

for a middle

Break pause-to-paint into its terms, say who controls each, and explain the paint guard: tag requests with their text, cache every response, paint only the current one.

for a senior

Argue from field data: the slow tail on mobile, why the delay stays short, what warming the connection and small payloads buy, and what the list shows when the answer is late or fails.

for a principal

Treat the budget as a contract between the client and the suggestion service: who owns which milliseconds, how the split is measured, and what happens when one side overspends.

## The budget the user actually feels For a typeahead the number that matters is **pause-to-paint**: the time from the moment the user stops typing to the moment suggestions for that text are on screen. It is a sum, and each term has an owner. The figures below are illustrative for a **music-streaming web app** used on phones; real ones come from field measurement. | Term | Illustrative share on a mobile network | Who controls it | |---|---|---| | Typing delay | 100-250 ms | the client, freely | | Connection set-up | zero if warm, several round trips if cold | the client, by warming it early | | Round trip | 100-300 ms, more on a poor signal | partly the client: payload size, one host | | Server time | tens of milliseconds | the suggestion service | | Parse and render | a frame or two | the client | A common target is that suggestions land within a few hundred milliseconds of a pause, the point where they still feel like a reaction to typing. On office Wi-Fi that is easy; on a train the round trip alone can use most of it. ## Spending the budget 1. **Keep the delay short.** The delay is the only term that is pure waiting: it is added to every suggestion and buys fewer requests in return. With a 200 ms round trip, raising the delay from 200 to 400 ms turns a 400 ms wait into 600 ms for little gain. Start around 150-200 ms and tune on real data. 2. **Set the minimum length per script.** Two characters for Latin text, one where a single character is a word. Below it, show only local matches (recent searches, the saved library), which cost nothing. 3. **Remove set-up cost.** Open the connection to the suggestions host when the box gains focus, with a preconnect hint or a cheap warm-up request, so the first query does not also pay for name lookup and the TLS handshake. 4. **Keep responses small.** A handful of results per group, artwork as small image URLs loaded lazily rather than anything inline. 5. **Skip the delay on a cache hit.** Backspacing to text already answered should repaint at once. ## Which response may paint Requests can come back out of order, so the box applies **latest-wins** as a policy: - tag each request with the **normalised text** it asked about; - when a response lands, **store it in the cache** under that text, then paint it **only if** that text equals the current normalised input; - never let a response **replace a list painted for newer text**; - cancel superseded requests where the request layer allows. Cancelling saves bandwidth, but the paint guard is what keeps the list correct, because a response may already be on the wire. ## What the list shows while the next answer is in flight - Keep the **last painted list**, filtered down to rows that still match the current text, rather than clearing it to a spinner. - Show a **quiet progress cue**: a thin bar or an indicator inside the input. - Update the **local section on every keystroke**; it never waits. - Show **"No results" only** when the response for the current text is empty. - On failure, keep the local section and show a short inline message. The next keystroke is the retry; do not loop retries while the user is still typing. - If the input is cleared, show recent searches and let pending answers go unpainted. ## Measuring it A budget is a claim until it is measured. Record pause-to-paint from real sessions, split by connection type, and watch the slow tail rather than the median: the user on a weak signal is the one who abandons the box. How that measurement is collected and shipped belongs to the app's telemetry design. ## Summary The delay buys fewer requests at the price of latency on every suggestion, so it stays short; the network share is cut by warming, shrinking and caching; and a single rule, paint only the answer for the text in the box, decides which response the user ever sees.

  • Should the typing delay adapt to the network?
    It can, within limits. On a slow link a slightly longer delay avoids queuing requests that will be superseded, but every extra millisecond is added to the wait the user already feels. A safer first move is to keep the delay short and cut the network share: warm the connection, shrink the response and lean on the cache. Adapt only if field data shows queued requests hurting.
  • A response for the current text arrives empty, but the previous list had matches. What does the user see?
    "No results" for the remote part, with the local section still showing any recent searches or library matches. The empty answer is for the text in the box, so it is now the truth; keeping the older list would show suggestions that do not match. Offering a spelling suggestion or a link to full search is a product choice on top.
  • Why not cancel stale requests and skip the paint guard?
    Because cancelling is best effort. A response can already be on the wire, or arrive in the same moment the next keystroke lands. The guard compares the response's text with the current input, so even a response that escaped cancellation cannot paint over a newer list.

  • Paint whichever response arrives last; it must be the newest one.
  • The typing delay is free; only the server's time counts against the budget.
  • Clear the list to a spinner whenever a new request goes out.
  • Show "No results" as soon as the old list filters down to nothing.
  • Round-trip time is the network's problem; the client cannot change it.
  • Aborting stale requests alone guarantees an old answer never paints.