Rate limiting and abuse protection for small APIs

Published 2026-11-06

Every public endpoint gets probed

Within hours of going online, a new site receives automated requests: scanners looking for known admin paths, bots trying common passwords and scrapers collecting content. Most are harmless noise, but a few are not, and all of them cost bandwidth and compute. Protection does not need to be elaborate to be effective.

Layer 1: the edge

A proxy or CDN in front of the application can block known bad traffic, challenge suspicious clients and absorb floods before they reach your server. Turn on the managed rules your provider offers, and add a rule for paths that no legitimate visitor requests, such as common admin panels and configuration files you do not run.

Layer 2: per-route limits in the app

Framework rate limiters let you cap requests per minute by IP address or user. Be strict where abuse is costly: login, registration, password reset, contact forms and anything that sends email. Be generous on cheap, cacheable reads. Return a clear 429 status with a retry hint, so well-behaved clients slow down.

For login, limit by both account and address, and consider a short, growing delay after repeated failures. Pair this with two-factor authentication for privileged accounts.

Layer 3: make forms hard to abuse

  • A hidden honeypot field that humans never fill in.
  • Server-side validation for every field, whatever the browser does.
  • A challenge only when behaviour looks automated, to avoid punishing normal users.
  • Queue outgoing email and cap it per recipient.

Watch and tune

Log blocked and limited requests with the path and a coarse client identifier, and review them occasionally. A sudden spike on one route tells you where to tighten. Avoid logging passwords or tokens, and keep logs only as long as needed. Remember that robots.txt is a courtesy for polite crawlers, not a security control; use real access control for anything private.

Choosing limits that fit real use

Limits should be high enough that no honest user notices and low enough that automation hurts. Measure normal behaviour first: how many login attempts a person makes in a minute, how often a dashboard refreshes, how many messages a contact form should ever receive from one visitor. Set the limit a few times above that, then tighten as you learn.

Different routes deserve different budgets. Sign-in, password reset and registration are expensive to abuse and cheap to protect; a read-only public page can afford a generous ceiling.

Responding well

  • Return a clear 429 status with a Retry-After header, so well-behaved clients slow down.
  • Do not reveal whether an account exists in error messages on login and reset forms.
  • Prefer a challenge or a delay over a permanent ban, since shared networks hide many real users behind one address.
  • Keep an allow list for your own monitoring so it never blocks itself.

Costs of ignoring it

Abuse is not only a security problem. Bots that hammer an endpoint consume compute and bandwidth you pay for, fill your database with junk and drown real signals in the logs. A few hours spent on layered limits is cheaper than the first incident.

© 2026 The Good Fellas