Pricing
5 min readplacescost

Debouncing autosuggest: the cheapest 60% you will ever save

Per-keystroke address search bills per keystroke on every provider. A 150-millisecond debounce and a two-character floor typically remove two thirds of the calls without a user noticing anything.

Autosuggest is the one endpoint where a naive integration can multiply your bill by four without anybody noticing. Every keystroke is a request, and a typical address is eighteen characters.

The three cheap wins

  • Debounce at 150 ms. Below that you are billing for typing speed; above 250 ms it starts to feel laggy.
  • Do not fire below three characters. Results at one or two characters are noise anyway.
  • Cancel in-flight requests when a new keystroke arrives — an aborted request that never lands is still billed, but you avoid rendering a stale list.
js
let timer, controller;

input.addEventListener("input", (e) => {
  const q = e.target.value.trim();
  clearTimeout(timer);
  controller?.abort();
  if (q.length < 3) return;

  timer = setTimeout(async () => {
    controller = new AbortController();
    const res = await fetch(
      `https://api.apinavi.com/v1/autosuggest?q=${encodeURIComponent(q)}&at=${at}`,
      { headers: { Authorization: `Bearer ${key}` }, signal: controller.signal }
    );
    render(await res.json());
  }, 150);
});

What it actually saves

On an eighteen-character address, an undebounced field sends sixteen requests. With a three-character floor and a 150 ms debounce, a normal typist sends five or six. At $1.00 per 1,000 that is the difference between $16 and $6 per thousand completed addresses — and it costs one afternoon.

The same maths applies at any provider. We mention it because a vendor whose revenue rises with your inefficiency has no reason to write this post.

All posts