How best to configure Railway services for coast to coast (us-east & us-west) load balancing?
We currently have a Railway project with an Express API service hosted on US East (Virginia, USA) region. This service also has 3 replicas.
We are thinking of spinning up a duplicate setup, but on the US West (Oregon, USA) region.
What is the best way to configure this? Is it as simple as creating a new service and pointing it to the same GH repo? But instead of selecting US East as the region, select US West? We have most of this config in a railway.json file.. so I am thinking we will probably need a railway-us-east.json and railway-us-west.json config file, right? And then I would imagine we need some new domains, ie us-east-api.service.com and us-west-api.service.com ... and finally a load balancer like Cloudflare to direct traffic accordingly based on geo. Am I missing anything?
Solution:Jump to solution
hey @Ramin - a little late but we wanted to perfect it, here is the tutorial!
https://docs.railway.app/tutorials/proximity-steering...
13 Replies
Project ID:
7f34b4f7-9d09-48a8-997c-32a10e59c1eb
7f34b4f7-9d09-48a8-997c-32a10e59c1eb
cc @Brody as he mentioned that he wanted a guide here, we'd publish one on the docs if you are willing to write one
yes id write one, just need a paid cloudflare account
What is the best way to configure this? Is it as simple as creating a new service and pointing it to the same GH repo? But instead of selecting US East as the region, select US West?Its actually even simpler, just right click a service, click duplicate, go into the duplicate services settings and change the region, then deploy.
We have most of this config in a railway.json file.. so I am thinking we will probably need a railway-us-east.json and railway-us-west.json config file, right?for ease of use, i would remove the region option from the railway.json so it can be set in the service settings.
And then I would imagine we need some new domains, ie us-east-api.service.com and us-west-api.service.comcorrect!
and finally a load balancer like Cloudflare to direct traffic accordingly based on geoindeed! cloudflare (only on the paid plan) lets you set up geo load balancers where you select a region on a map that will correspond to the upstream host, in your case either the us-west or us-east endpoints, make sure you overwrite the host when configuring your upstreams!
Am I missing anything?nope, thats about all i can help with initially, happy to write up a guide but i dont have access to a paid cloudflare account.
You the best. thanks!
no problem!
question re: ENV vars. Whats the best way to keep those in SYNC between these new services
personally i would designate a single service (us-west imo) to be the keeper of environment variables, then just referance all the variables on the us-west service from any of the other services
so lets go through the "adding a new ENV var" scenario. I go to the us-west service, navigate to "Variables" and add "+ New Variable" ... now that service is waiting deployment for the ENV var to be available.
At this point, do I Deploy the changes, navigate to the us-east service, and ..... ?
for this example lets add a variable called
MODE
that we want to set to production
and that our service in the us-west region is named simply us-west
-
open the us-west service, add the variable that was mentioned, open us-east and add MODE=${{us-west.MODE}}
, and only then deploy the changesahh, ok. thank you!
let me know if you need any more help!
Solution
hey @Ramin - a little late but we wanted to perfect it, here is the tutorial!
https://docs.railway.app/tutorials/proximity-steering