Phoenix Channels on Heroku apps with multiple dynos

Hello! I have a phoenix 1.4 app running nicely on a single dyno in Heroku.

I’ve tried scaling it up to 2 dynos and it also runs great, except for channels (that I use so background jobs can notify of finished processing, and the UI is updated).

It seems that when I have 2 dynos, some messages are not received on the channel. There’s no error, just lost messages.

I’m on Phoenix.PubSub 1.1.2 and using the Phoenix.PubSub.PG2 adapter - is it supposed to be compatible with Heroku? Should I use the Phoenix.PubSub.Redis adapter instead?


1 Like

those two servers should be run in a cluster which I believe you can’t on heroku (except perhaps using their enterprise “private spaces” product)

I think you can switch from PG2 to using the redis adapter which should then work…

but honestly I would scale to a single larger dyno eg standard 1x/2x/performance M etc… but are you already saturating the “large” dynos?

1 Like

Thanks, I see, I can consider using the Redis adapter then.

You’re also right that I can first try to upgrade to a larger single dyno.


For anyone from the future who lands here, the next bottleneck will be on number of simultaneous connections. The wisdom is that you can have 50/dyno/heroku router - with the number of heroku routers being unknowable and the balancing strategy also unknowable. I also had issues with session affinity.

However, this connection limit did force me to use more smaller dynos, vs single larger dyno. I’m off to try the redis adapter for this reason as well.

1 Like

You are very unlikely to run into that 50/dyno/heroku router limit since Heroku has so many routers. It is completely feasible to have 1,000+ simultaneous Phoenix Channels open on a single Heroku dyno. Here’s an example from people that have tested that:

Now this will definitely be a problem, and of course since Heroku does not allow connections between dynos you cannot cluster on Heroku which could be used as a partial workaround for this (unless you get a Heroku Private Space which costs serious money)