Feature request: Current amount of requests on a specific route - inside workers

#1

There are so many use-cases where we need to rate-limit, like:

  • E-mails like notifications/reminders, token requests etc.
  • Sending requests to 3rd party services
  • Uploading files of any type

However, due to the nature of workers we cannot do that reliably since state doesn’t persist - which enables DDOS attacks easily even with small amount of traffic.

If we could get a feature to count the total amount of requests on a specific route inside workers, this wouldn’t be a problem.

Something like requestCount('/mail') and it could retrieve an object like:

{
 lastSecond: 1,
 lastMinute: 3,
 lastHour: 423,
 lastDay: 4325
}

Since you’re already counting requests, maybe this is possible?

Global, decentralized leader selection with Workers KV, was: Fetch() with a client certificate?
#2

I guess a simple kind of worker-queue would work as well (and be more flexible) - where we can assign a task (function or route) to be done and we can limit the speed of the task-queue.

#3

The short answer is: you’re absolutely right. The ability to do atomic counting and to create a queue would both be exceptionally powerful. As you can imagine it’s tricky to balance with all the other priorities we have around improving the Worker’s experience, but we’re absolutely on the same page.

2 Likes
#4

That’s just the answer i was dreaming of, keep up the great work! I absolutely love it so far :heart: