Serksa
All Concepts
Performance & Scaling

Debouncing vs Throttling

1

What is it?

<strong>Debouncing</strong> delays execution until after a pause in events, while <strong>throttling</strong> limits execution to once per time interval. Both optimize performance by reducing function calls.

2

Think of it like...

The Elevator Analogy

Debouncing: Elevator waits 5 seconds after last person enters. Throttling: Elevator leaves every 30 seconds regardless of how many people arrive.

🛗

Debouncing (Wait for Everyone)

Delay until no more people

⏱️

Throttling (Every 30 Seconds)

Go at fixed intervals

👥

People (Events)

Keep arriving

3

Visual Flow

⌨️Events

User Input

⏱️Debounce/Throttle

Control Execution

⚙️Function

Executes Optimally

4

Where you see it

1

Debouncing: Wait for pause

User types 'hello' → wait 300ms after last keystroke

2

Debouncing: Execute once

Only call API after user stops typing

3

Throttling: Execute at intervals

User scrolls → execute every 100ms max

4

Throttling: Ignore extra calls

Discard calls that happen within interval

5

Common Mistake

Wrong

"Debouncing and throttling are the same"

Correct

<strong>Different use cases</strong>. Debouncing: Search input (wait for user to finish). Throttling: Scroll events (limit frequency). Debouncing delays, throttling limits rate.

💡 Real-World Example

When to use each:

1

Debouncing: Search autocomplete (wait 300ms after typing stops)

2

Debouncing: Window resize (recalculate layout after resizing stops)

3

Throttling: Infinite scroll (check scroll position max every 200ms)

4

Throttling: Mouse move tracking (update position max 60 times/second)