Deploying in all regions and directing users based on location

The main thing that matters about my app is the fact that users are as close to the server as possible.

I use Fly because it is the easiest way to get an app deployed in multiple regions.

Currently, I have the Pro plan on Fly and I have it set it up so that all regions are available. I set the minimum count to 20.

I have encountered 2 problems:

  1. Instead of 1 deployment per region, I see multiple deployments in the same region. Can I set the limit to 1 deployment per region?
  2. My users have their requests sent to regions that are not the closest one for them. For example, I am in California and rather than sending me to any of the 3 deployments in California, my traffic is routed to New Jersey or even Chicago sometimes. Is there a way to make sure that the server that my user’s traffic hits is one that is closest to them?

Can you copy paste the output of flyctl scale show and flyctl regions list?

Generally speaking you will be routed to whatever region is closest network topology wise. This probably means that for whatever reason ewr or ord have a lower latency from your network. Check out this page: https://liveview-counter.fly.dev/. If you scroll to the bottom it will show you the region that you are connected to by default with the latency shown.

1 Like

Here are the responses to your question @DAlperin

Even though when opening the liveview link you sent it shows me LAX, when running the app on simulator my app connects to the sever in New Jersey.

❯ fly scale show
VM Resources for un1feed-staging
        VM Size: shared-cpu-1x
      VM Memory: 512 MB
          Count: 20
 Max Per Region: Not set
❯ fly regions list
Region Pool: 
ams
cdg
dfw
ewr
fra
gru
hkg
iad
lax
lhr
maa
mad
mia
nrt
ord
scl
sea
sjc
syd
yyz
Backup Region: 

You can pass max per region to the scale command: fly scale count 15 --max-per-region=1. Just make sure you have enough regions enabled for the count you’re requesting. You’ll also need to use fly deploy --strategy rolling with that setting.

https://debug.fly.dev will have a better look at what routing is doing for you. You’ll see a Fly-Region header that indicates the region we saw your connection in.

2 Likes

It says lax on that website too, but when running the app from my simulator it always connects to NJ.

What is simulator? I will see if I can replicate.

It is working perfectly fine now, not sure what happened!

(fyi by Simulator I meant iPhone/Android Simulator)