What is the best way to throttle api to
What is the best way to throttle api to another rest api endpoint in a worker? The rest end point has a 60 requests/sec hard stop
5 Replies
Workers have no concept of time so this is where i'm running into issues
"no concept of time"?
that's just not true
Security model · Cloudflare Workers docs
This article includes an overview of Cloudflare security architecture, and then addresses two frequently asked about issues: V8 bugs and Spectre.
yes, I'm aware. that is completely different than "no concept of time"
if you are calling a rest api the time will reset each time, as those docs you link clearly state. so you can do the rate limiting based on that
or don't overcomplicate things and simply call the rest api and just handle 429 with exponential backoff
Most rate limits will have a header with the amount of time you need to wait for in the 429 response, so you can typically wait for that much time and then try again