API Fundamentals Course
API Fundamentals
/
Intermediate

Rate Limiting

Definition

A technique used to control the rate of traffic sent or received by a network interface. It is used to prevent DoS attacks, brute-force login attempts, and excessive API usage.

Explain Like I'm New

The bouncer at a club. If you ask to get in once, he says yes. If you ask to get in 1,000 times in 10 seconds, he assumes you are a robot (or an attacker) and blocks you for 15 minutes.

Real World Example

Limiting the `/login` API endpoint to 5 requests per minute per IP address. If a hacker tries to guess passwords rapidly, they will quickly be locked out, receiving a `429 Too Many Requests` status code.

Common Use Cases

  • •API monetization
  • •Security against brute-force
  • •Preventing server crashes

Interactive Example

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

Interview Questions

basic

  • What HTTP Status code should a server return when a user hits a rate limit?

intermediate

  • If a malicious user uses 50,000 different IP addresses (a botnet) to bypass an IP-based rate limiter, how do you stop them?

Flash Cards

Question

Which status code?

Click to reveal answer
Answer

`429 Too Many Requests`.

Question

How to stop botnets?

Click to reveal answer
Answer

You must rate-limit based on the specific User Account or API Key, not just the IP address. Alternatively, you put a massive Cloudflare WAF (Web Application Firewall) in front of your API to analyze the bot traffic patterns.