I have a use case where I’d like Fly Router to apply regional and machine instance affinity by subdomain.
For example, foo.mysite.com will always be routed to a machine in the lax region, and always the same machine instance if already running, while baz.mysitcom will always go to a machine instance in fra.
A couple solutions I can think of on the top of my head:
In application layer (middleware)
a. Look at header.host and pick out subdomain
b. based on subdomain, set sticky session via: Session Affinity (a.k.a. Sticky Sessions) · Fly Docs
c. NOTE: this requires a hop and will hit a random instance on the first request.
In your DNS, eg Cloudflare, you can use the Transform Rules based on URI
a. eg: https://foo.mysite.com/* => add headers "Fly-Replay": "instance=<LAX-instance-id>"
b. NOTE: this is static and you won’t be able to make sure of the fly proxy to handle scaling. Point 1 will be able to handle the dynamic-ness