Node.js Course
Node.js
/
Intermediate

Rate Limiting

Definition

A technique used to control the amount of incoming requests to a network or server within a specific timeframe to prevent abuse.

Explain Like I'm New

A bouncer at a club. If one person tries to enter the club 50 times in 1 minute, the bouncer steps in, blocks them, and says 'Slow down, wait 15 minutes'. This stops hackers from brute-forcing passwords or crashing your server via Denial of Service (DDoS) attacks.

Real World Example

Using the `express-rate-limit` package. Setting a rule that allows a single IP address to hit the `/login` endpoint a maximum of 5 times per hour. If they fail 5 times, they are locked out.

Common Use Cases

  • •Preventing brute-force login attacks
  • •Preventing API abuse / DDoS
  • •Monetizing APIs (e.g., Free tier gets 100 requests/day)

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What HTTP status code is returned when a user exceeds the rate limit?

intermediate

  • Why is storing rate limit data in Node.js memory a bad idea for large apps?

Flash Cards

Question

What status code?

Click to reveal answer
Answer

429 Too Many Requests.

Question

Why is memory storage bad?

Click to reveal answer
Answer

If you run 3 instances of your Node server behind a load balancer, they don't share memory. A hacker could hit Server A 5 times, Server B 5 times, and Server C 5 times, effectively bypassing the limit. In production, rate limits MUST be tracked in a centralized fast database like Redis.