R
Railway5mo ago
Ramin

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:
hey @Ramin - a little late but we wanted to perfect it, here is the tutorial! https://docs.railway.app/tutorials/proximity-steering...
Jump to solution
13 Replies
Percy
Percy5mo ago
Project ID: 7f34b4f7-9d09-48a8-997c-32a10e59c1eb
Ramin
RaminOP5mo ago
7f34b4f7-9d09-48a8-997c-32a10e59c1eb
angelo
angelo5mo ago
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
Brody
Brody5mo ago
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.com
correct!
and finally a load balancer like Cloudflare to direct traffic accordingly based on geo
indeed! 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.
Ramin
RaminOP5mo ago
You the best. thanks!
Brody
Brody5mo ago
no problem!
Ramin
RaminOP5mo ago
question re: ENV vars. Whats the best way to keep those in SYNC between these new services
Brody
Brody5mo ago
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
Ramin
RaminOP5mo ago
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 ..... ?
Brody
Brody5mo ago
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 changes
Ramin
RaminOP5mo ago
ahh, ok. thank you!
Brody
Brody5mo ago
let me know if you need any more help!
Solution
Brody
Brody4mo ago
hey @Ramin - a little late but we wanted to perfect it, here is the tutorial! https://docs.railway.app/tutorials/proximity-steering
Want results from more Discord servers?
Add your server