Fan Out WebWorkers by Region?


#1

Is it possible to have a single web worker, fan out a request to other webworker nodes by region? I want to specify my requests by region for my specific business case as its important.


#2

I’m also in need of this, mostly for GDPR reasons (Keep requests in EU, or even single country)


#3

I am not sure if I understood your requirement clearly. In general, once a request reaches the worker, you can access the ‘CF-IPCountry’ header and use it to direct to appropriate origin.

But I am not sure if Cloudflare guarantees user request (from browser to the edge) to be within the region. Some times they travel a long distance, especially for free plans.


#4

I want to be able to specify a region for my request to run from.


#5

I don’t think it’s possible currently. As Jay said above, you can access request.cf.country which is the user’s GeoIP country so that you can check if the user is part of the EEA and perform necessary redirects/actions, but this code you deploy will be ran, and billed. in every Cloudflare datacenter and country.


#6

You could use request.cf.colo, it refers to the datacenter running the worker. Throw an error when outside the GDPR area (EU and EEA).

This is what I use:

const gpdr_colo = ['ams','arn','ath','bcn','bru','bud','cdg','cph','dub','dus','edi','fco','fra','ham','hel','kef','lhr','lis','lux','mad','man','mrs','muc','mxp','osl','otp','prg','rix','sof','tll','txl','vie','vno','waw','zag','zrh']


#7

How does this guarantee the worker will still run though? Doesnt this just prevent the worker from running in one of those? Would be better if I could specify a geographic region at minimum during my request so it c as n at least guarantee me it will somewhere in that region.


#8

Workers will always run, you could run code differently depending on the datacenter request.cf.colo, your code will propagate globally within CF datacenters.


#9

To expand on @adaptive’s post, you can’t specifically run in a certain datacenter due to how anycast works.


#10

What? Are you saying my worker will run on every single edge server no matter the request origin? I don’t that’s true…


#11

By region would be the feature request, not specifically data center. I ha e found a way around it by setting up multiple origin servers in same region and initiating my calls from those does appear to make the worker run in that region due to Anycast. Would be nice if I could just specify region though overriding that…


#12

In a simple explanation, your worker code is distributed opportunistically across Cloudflare global datacenters.
Every time a client requests it, it will run on the datacenter closer to that client, hence the name “edge computing”.


#13

Dont get snarky I understand what edge computing means bud. I want to hit edge nodes by region, it’s not a difficult concept and its something I should be able to do…


#14

Let’s keep the tone down, that is the basis of every civilized discussion.

What are you exactly trying to accomplish? You want to run different version of the worker code depending on the region your webworker is? Depending on where the worker runs?

As I understand it you want to know the region where the requests to Cloudflare arrive. You simply can’t due to the nature of the anycast network, not even all requested from a single location are guaranteed to a single POP. If you want a fixed location you should go with AWS Lambda, Google Cloud’s Cloud Functions or Azure Functions. Workers are per definition edge computing running on all datacenters, which is what makes them unique and wonderful, but not for every use case.


#15

My scenario is to have a single worker able to fan out requests to hundreds of other workers around the world and process data points that the user sets up. The data being returned will be different based on the region where these workers run, but what I want to get back is the results from all of them and where each one ran. Yes I am already using an Azure Function in every region to accomplish this but I wanted to add CloudFlare data to my app as well. I am being vague as to not give away what we are doing exactly. Just know for specific business cases the data is different based on where it runs and that’s the important detail to our offering.


#16

Then Cloudflare Workers won’t work for you. The definition of Workers is to have a single codebase running as close to the user as possible. You can’t set a single POP where the code is run, all or nothing.


#17

That’s unfortunate, that would be very powerful.


#18

I can agree with you, but that would add a ton of complexity. Imagine having to selectively abilitate the script on each edge node. They would have to have specific IPs for each of them. This would also prevent them from actually doing what they are best at and protect from DDoS since bad actors could target specific IPs and specific nodes.