A rate limit caps how many requests one client can make in a period of time: say, 5 login attempts a minute, or 100 API calls a minute per key. Without one, a single script can guess passwords all night, scrape your whole catalogue, or run up your AI bill, and one busy client can slow the app down for everyone else. The examples below are Node.js rate limiting with Express middleware you can copy.
What to limit, and by what
Two choices define a limit:
The key : who counts as “one client”. Usually the API key or user ID when the request is signed in, and the IP address when it isn’t. IPs are shared (an office, a mobile network) and easy to change, so limits by IP should be generous.
The scope : which requests count.…