I have a site that doesn’t get a lot of requests. When it does though they are multiple simultaneous requests from the same origin which I assume would be directed to the same data center.
When request 1 comes in I want to store a value in a global variable so that simultaneous requests 2, 3, and 4 from the same origin don’t attempt to duplicate the same work completed by request 1. When request 1 finishes the global variable should then be unset. Requests 2, 3, and 4 would probably then await on a setTimeout until the global variable is cleared and then continue.
My understanding is that you want Serialize the Incoming Request to a Worker inside a POP Location
using a global Semaphore Variable.
I dont think there is a possiblity to serialize this requests is it will garbage and disrupt the operations of other clients.
There is no general limit to the number of requests per second Workers can handle.
Cloudflare’s abuse protection methods do not affect well-intentioned traffic. However, if you send many thousands of requests per second from a small number of client IP addresses, you can inadvertently trigger Cloudflare’s abuse protection.
The Only was to do something like this is to work
with Durable Objects which allows synchronisation of parallel requests.
If needed is also possible do websocket connection to this durable object for each requests
and then do polling inside the websocket connection.
It means you will have still have dozens of parallel request open but with the Durable Object and the Websockets connection to this Durable Object Sempaphore you can serialize the behavior of the requests after they were established.
Example: An atomic counter
Here’s a very simple example of a Durable Object which can be incremented, decremented, and read over HTTP. This counter is consistent even when receiving simultaneous requests from multiple clients – none of the increments or decrements will be lost. At the same time, reads are served entirely from memory, no disk access needed.