What is Debouncing & Throttling?
Why Your App Fires 100 Requests When It Only Needs One
Ever typed into a search box and watched your browser slow to a crawl? Every single keystroke was firing an API call, hammering the server with requests for "h", "he", "hel", "hell", "hello." That's an app without debouncing, reacting to every tiny input instead of waiting for you to finish.
Two Ways to Stop Overreacting
Debouncing = wait until the user stops acting, then fire once. Throttling = fire at most once every X seconds, no matter how often the user acts.
Debouncing and throttling are frontend techniques. They reduce how often your code runs. Rate limiting (another Building Block) is the server-side version: it rejects requests that come in too fast. Think of debounce/throttle as the polite caller who waits before dialing, and rate limiting as the receptionist who hangs up on the 11th call per minute.
When to Use Debouncing & Throttling
Debouncing & Throttling isn't always the right call. Here's a quick mental model:
Search boxes or autocomplete fields
Users type fast. Debounce so you send one request after they pause, not one per keystroke
Scroll, resize, or drag events
These fire dozens of times per second. Throttle to run your handler at a sane rate (every 100-200ms)
Auto-save or form validation
Debounce so the save or validation triggers after the user stops editing, not while they're mid-sentence
You're hitting API rate limits or high costs
If your app sends too many requests and your server (or wallet) complains, debouncing the trigger is the cheapest fix
The action must happen instantly
A "Submit Order" button should fire immediately on click. Debouncing a checkout button would feel broken. Use it for background processes, not critical user actions
Events are already infrequent
If a button only gets clicked once every few seconds, there's nothing to debounce. Adding a timer just makes the app feel sluggish for no reason
Interactive Debouncing & Throttling Demo
Try both techniques side by side. First, simulate typing into a search box to see debounce in action. Then simulate rapid scroll events to see throttle at work.
AI Prompts for Debouncing & Throttling
Now that you understand debouncing & throttling, use these prompts with your AI coding agent. Copy the one that matches what you're building — the agent will handle the implementation.
Tip: These prompts work with any AI (ChatGPT, Claude, Cursor, Copilot). Just copy, paste, and fill in the [brackets]. You don't need to understand timer code. The AI will explain as it builds.
Common Debouncing & Throttling Mistakes to Avoid
Using throttle when you need debounce (or vice versa)
They solve different problems. Debounce waits for a pause in activity ("fire after silence"). Throttle limits frequency ("fire at most once per interval"). A search box needs debounce. A scroll handler needs throttle. Mixing them up gives you either delayed responses or still too many calls.
Setting the delay too high
A 2-second debounce on a search box makes users think the app is broken. Start with 300ms for typing inputs, 100-200ms for scroll/resize. Test it yourself: if it feels sluggish, lower the delay.
Forgetting to cancel pending work
If a user types "cat", waits, then types "dog", you might get results for "cat" arriving after "dog" results, overwriting the correct answer. Always cancel the previous API call when a new one starts. Tell your AI: "cancel the previous request when a new one fires."
Debouncing a button the user expects to work instantly
Never debounce "Submit", "Buy", or "Delete" buttons. Users click once and expect immediate action. If you're worried about double-clicks, disable the button after the first click instead. Debounce is for continuous input, not deliberate actions.
Related Building Blocks
Ready to Build Real Products?
Learn to ship MicroSaaS apps with AI in the Solo Builder course.