Is it possible to decide which machine to request to?

Let’s say i have a standard REST API deployed in 3 machines in different regions, and in a different application, I have a frontend. Is it possible to let fly know which machine to use and receive the frontend request based on the user configuration?

I want to know if this is possible because my app needs to test connections based on region.

Thanks is advance.

From How To to Questions / Help

I think a combination of the fly-prefer-region request header and fly-replay response header might be what you’re looking for here.

1 Like

@jssjr Interesting! Thank you for your reply.

Sounds like what i’m looking for, yet, i see that fly-prefer-region “attempts” sending a request to the region, which sounds non-deterministic, so I guess fly-replay could be more reliable.

Also, I see that the fly-replay has a limitation of “requests larger than 1MB”. Do you know if that refers to the size of the response content too?

Thank you!

I’ve been using fly-prefer-region for quite some time, and am happy with it. Obviously if there isn’t a machine running in that region at the time of the request, it will go some place else.

There also is a fly-force-instance-id, though I’ve never used it.

fly-replay’s limitation is just to request size.

Something that always works is a reverse proxy, like nginx will provide.

I use all of the above (except for fly-force-instance-id) “just in case”.


@rubys fly-force-instance-id sounds useful too, but I couldn’t find any documentation on it, how does it differ from the replay request to specific VMs?

Would you recommend using fly-prefer-region and replay applied in the same request? The thing is for my app, I need a 100% certainty that the request is being made to the selected region.

My app, too, needs absolute certainty and you can read how I support multiple regions.

As I type this, a user in Adelaide is using my app. I, sanely, put their database in syd. But for whatever reason their requests are arriving in hkg (I kid you not). At that point, the fly proxy takes over. It understand s fly-prefer-region and fly-force-instance-id, and the user’s requests contain fly-prefer-region so the requests are passed along to my server in syd.

Each of my servers is running nginx and know where all of the databases are located. So in the off event that a stray request arrives at the wrong location, I either respond with a fly-replay header if I’m confident that the request size is less than a megabyte, or reverse proxy using the internal private network.

The difference between these headers is fly-replay is something your SERVERS should respond with, and the others are things that your API should insert.


@rubys thank you so much for the clarification! The fly-prefer-region and fly-force-instance-id worked perfectly, I will be checking how could I validate the off event in which the request could land in an incorrect region machine now.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.