Poor man's API rate limiting
API Rate Limiting (“Poor Man’s” Style)
Why?
-
Protects your endpoints from abuse (bots, accidental infinite loops, brute-force).
-
Prevents a single user/client from overwhelming your service.
-
Even a simple rate limiter (requests per minute/hour) can prevent outages on shared infrastructure.
How?
-
For cPanel/Flask/MySQL, a simple pattern:
-
Use a table:
rate_limits (ip, endpoint, window_start, count) -
On each request, increment count for the
(ip, endpoint, window_start)row. If count > threshold, return 429. -
Cleanup old rows with a background task or on each request.
-
Alternatives
-
Store rate-limits in Redis if you ever get access.
-
For basic MVP, can even use an in-memory dict per process (works until you have multiple workers/processes).
Comments
Post a Comment