Session affinity ("sticky sessions")?

How can I do this? How do I prevent instances of the same app from being started in the same region? I am less concerned about tying each instance to a particular region and more with ensuring two instances of a given app don’t share a region…

When you add multiple regions, we spread instances out as much as possible. If you add, say, 5 regions and then run 4 instances, you should always get one per region on a deploy.

You can get really tight control over regions by adding volumes, if you need to. That would prevent a second instance from ever running in the same region.

Excellent! I’ll make sure I have more regions added than running instances.

I’m so pleased that everything is working out and I found my new app hosting platform! :grin:

1 Like

Hey, has there been any movement on either session or IP affinity since this post? I’m considering some changes to one of my apps and some kind of request affinity would really help. I often run more app instances than there are regions (often 25 or 30 containers) so regional affinity wouldn’t work for me.

No worries if no work has been done here yet! It’s useful to know either way so I can change my approach as necessary.


We haven’t done anything here yet! You can likely do this yourself with two apps:

  1. Haproxy or nginx with session affinity configured
  2. App instances listening on 6pn

Haproxy makes it very easy to configure load balancing across <region>.<appname>.internal, we use this for our postgres clusters: postgres-ha/haproxy.cfg at main · fly-apps/postgres-ha · GitHub

1 Like

--max-per-region is a neat command shared with me for future readers.

Full command looks like fly scale count 6 --max-per-region 1


Sorry to bring up an old thread, but I was wondering whether any further work had been done to enable Session Affinity within Fly? I’m sure a number of your customers (including me!) would find this particularly useful. Even a “soft” implementation would be of great help (not guaranteed, but highly likely). Thanks!

(cc @kurt)

Kurt has previously written about achieving “sticky sessions” with Nginx’s hash-based load balancing here: The 5-hour CDN · Fly