Subdomain affinity?

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.

Is this possible without a custom router?

A couple solutions I can think of on the top of my head:

  1. 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.
  2. 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

I didn’t know I could set a sticky session based on subdomain, that might be the key.

Yes, looking for something that can scale dynamically.

Thank you I’ll check it out more carefully!

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