I've enabled session affinity on Heroku via the CLI - is this enough to make sure traffic from a user hits the same process (Clustering using throng) on the correct dyno (multiple dynos)?

To be clear, I have no code to handle this. I just use socket io as is, I don't use sticky sessions or anything. All I've done is enable session affinity.

Is this enough? How can I test it locally?

1

There are 1 best solutions below

2
On

Not sure if you ever got this answered but thinking through this problem myself. Could potentially be enough, however, Socket.io calls out:

"if you are in a CORS situation (the front domain is different from the server domain) and session affinity is achieved with a cookie, you need to allow credentials:"

Source

Given you're using the default long polling then ws connection order, I think Heroku sticky sessions should be able to route your initial long-poll request to the right dyno. The two things I am unclear on:

  1. Once the long-polling request is distributed to the assigned dyno, does the upgrade to websocket connection also connect to the same dyno?
  2. Given that Heroku auto-scaler does not take websocket connections into account (source, search for websocket), how would you auto scale the dynos to account for traffic?

On number 2, it could potentially work via the long-polling API request p95 time being used to determine server load but unsure if API latency would increase due to websocket connections/workload.