Basic setup for distributed application using mix release

I haven’t been able to find a simple example for this. Let’s say we have a regular project with Phoenix that is deployed by building a mix release and copying that to a server.

Now if we want to run that application on two nodes, it is unclear what exactly needs to change I know it is necessary to set the RELEASE_DISTRIBUTION env var to name and set a unique RELEASE_NODE. The cookie should be the same, since it is set when the release is built.

But I’m wondering about the best way to actually connect the nodes when they are started. Also, is there anything else I’m missing?

The easiest way is to use libcluster for this, it does automatically a lot of things, like automatic connection, discovery etc.

Make sure to read about the available clustering strategies, the default one used by erlang is EPMD. Outside of EPMD, I’ve personally used in production Cluster.Strategy.Gossip with docker containers and it works out of the box.

2 Likes

Perfect, thanks!

The Phoenix generator, as of 1.7.8, includes dns_cluster. It’s a lot less featureful than libcluster, but if it does what you need it’s very convenient. With the minimal setup the Phoenix generator includes you only need to set the environment variable DNS_CLUSTER_QUERY to make it work.

3 Likes

That looks like it should be just enough for a simple use case. Thank you!