What is rate limiting and how to protect an API from excessive requests?

Published on 2026-10-20 by frfrand

What rate limiting is, user and IP limits, 429 responses, time windows, and when it can harm legitimate users.

What is rate limiting and how to protect an API from excessive requests?

Short answer: rate limiting is a technique that limits how many requests a client can make during a period or under certain rules. When the limit is exceeded, the API responds 429 Too Many Requests, ideally with Retry-After. The counter must be shared between instances and the limit, different according to the cost of each route.

It is used to protect APIs, prevent abuse, and distribute reasonably a capacity that is not infinite.

If someone sends thousands of requests per second to your login form, you might not want all of them to be served without restrictions.

A comparison with museum entries

Imagine a museum with space for one hundred simultaneous visitors. If it lets in a thousand people at once, the experience becomes bad for everyone.

Request limits serve a similar purpose: they allow managing the access rate so that a very active client does not consume all the service resources.

But an unfair policy must be avoided. If several families arrive on the same bus, blocking them because they share a source address would also be a mistake.

What can be limited?

You can establish rules by IP address, authenticated account, API token, or endpoint type. Each alternative presents trade-offs.

Limiting only by IP can affect people who share a residential, corporate, or mobile connection. Limiting by user requires identifying them. For critical endpoints, several combined strategies can be applied.

Business logic matters: querying a public product does not cost the same as generating a heavy report or sending an email.

How is it implemented?

A simple strategy is to allow a certain number of requests within a time window. There are also models such as token bucket, which allow controlled bursts and recover capacity progressively.

You don't need to memorize the formulas to understand the goal: establish a sustainable rate without unnecessarily punishing legitimate visitors.

In systems with multiple servers, coordination matters. If each instance counts requests separately, adding instances can accidentally multiply the allowed limit.

What is HTTP error 429?

When a client exceeds the policy, the server can return status 429 Too Many Requests. Some responses include Retry-After to indicate when it is appropriate to try again.

The client application should respect the limits and not retry in an aggressive loop. Otherwise, a system that is trying to protect itself will receive even more traffic.

Rate limiting and DDoS are not the same

Application limits help with certain abuses, but they cannot always stop a volumetric attack that saturates the network before reaching your server.

For those scenarios, upstream defenses, distribution networks, and specialized services are important. Rate limiting is one layer, not a magic solution against all threats.

Example: a report generation API

An API allows exporting reports that take twenty seconds to prepare. You can limit the number of concurrent jobs per account and move generation to a queue.

This protects the server and prevents one person from accidentally launching hundreds of identical jobs. Instead of returning unexpected errors, the system can inform that the task was scheduled or that a quota was temporarily reached.

Common mistakes

An identical limit for all routes: a status query and a costly export do not have the same needs.

Not explaining the rejection: the client interprets 429 as an outage if they do not know when to retry.

Blocking by IP without context: legitimate users behind the same network end up affected.

Trusting the limit as authorization: a person without permissions should not be able to perform an operation even once.

How to apply it in ArduMaker?

On a VPS from ArduMaker where an API is deployed, you can implement limits in the backend or in the VPS's nginx, considering how many instances exist and where the counter is shared. Redis, which is installed as an app on the VPS, can store that shared counter, although the exact choice depends on the architecture.

If you limit by IP, take it well. Requests to a domain arrive through the host's nginx, which replaces the X-Real-IP header with the visitor's real IP, and the VPS's nginx only trusts that header when it comes from the host itself. Use that IP, not the first value of X-Forwarded-For, which the client can invent.

ArduMaker's own MCP is an example: it allows up to 20 calls per second per connection, responds limite_excedido with the wait seconds, and counts in the database and not in memory, because it runs on multiple processes and a per-process counter would multiply the limit.

In one sentence: rate limiting allows saying "this far, for now" to protect service availability. It works best when it responds to the real cost of each action and does not become an obstacle for legitimate users.

Frequently asked questions

**What is the difference between a fixed window and a token bucket?** The fixed window counts requests per interval (for example, 100 per minute) and can let bursts through when the minute changes. The token bucket replenishes capacity little by little and allows short bursts without exceeding the average.

What should a client do when receiving a 429? Wait for what Retry-After indicates or, if it does not come, retry with increasing waits. Retrying in a loop worsens the problem.

Related: What is a DDoS attack.

Sources: RFC 6585: status 429 · Retry-After header.

What is rate limiting and how to protect an API from excessive requests?
  • API
  • rate limiting
  • seguridad

Keep reading

All articles · VPS plans