Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scaling phoenix on heroku

I dont have a tonne of experience with heroku, and even less with phoenix, so this may be a stupid question... but want to make sure I am making a good choice on hosting :)

From what I understand, the way you scale phoenix is add another server, launch another node, and connect them, then let BEAM / OTP work its magic to handle work load balancing. On heroku, dynos can't really talk together over a local network, which from what I understand is something that BEAM requires to cluster. So adding dynos will result in a more "traditional" scaling model, where you have an external load balancer balancing connections between unconnected nodes, with the db being shared state.

My question here is how big of an impact will this have? Is it more only an issue when you are hitting serious levels of load / scale, or will it mean spending a lot more money on infrastructure then is necessary?

like image 749
Matt Briggs Avatar asked Mar 31 '16 16:03

Matt Briggs


People also ask

Does Heroku support Elixir?

Heroku has this idea of buildpacks, which transform your code into a slug that can be run on their platform and abstract all the complexity. They support a small range of popular programming languages using these buildpacks, however Elixir is not one of them.


2 Answers

You'll get the best performance on a host that supports clustering, but Phoenix has a PubSub adapter system exactly for deployments like heroku: https://github.com/phoenixframework/phoenix_pubsub

One line config change and mix.exs deps entry and you'll have multinode channels on heroku via our Redis adapter.

like image 54
Chris McCord Avatar answered Sep 23 '22 02:09

Chris McCord


This is very open question, so I am sure my answer won't be comprehensive.

In your situation the most important question is: will I Phoenix use channels?

If you use plain old HTTP, it can be mostly stateless. There are lots of methods to simulate stateful connection like storing sessions in cookies. At the end of the day, it doesn't matter if your backend servers are connected with each other, because each of them is doing independent computations. Your load balancer can randomly select any server and it will always work. This cool feature of http enables this protocol to scale so well. You can definitely use Heroku in that scenario and it will work great.

If you use Phoenix channels, things get complicated. You still want to be able to connect to any of the servers, but you will probably send messages to other users real time and they can be connected to other servers. Phoenix solves this problem for you by clustering using BEAM and this will be hard on Heroku. Or even impossible.

To sum up: it is not a question of small scale/big scale. It is a question of features. Scaling channels will require clustering, scaling plain old HTTP will not.

like image 20
tkowal Avatar answered Sep 25 '22 02:09

tkowal