Use Channels in a Cluster

Learn about using channels in a cluster.

Cluster

It’s critical to run multiple servers when deploying a production application. Doing so provides benefits for scalability and error tolerance. For example, the ability to double the number of servers in the event of a higher load is much more powerful than doubling the number of cores on a single server. It can take a few minutes to add more machines but could take much longer to move the application to a different machine with more cores. There may also be a time when a single machine is fully utilized, and we cannot add more CPU cores or memory.

Elixir makes connecting a cluster of BEAM nodes very easy. However, we have to ensure that we’re building our application to run across multiple nodes without error. Phoenix Channels handles a lot of this for us because PubSub is for all message broadcasts, which we’ll look at next.

Connecting a local cluster

Let’s jump right in by starting a local Elixir node (an instance of our application) with a name:

Get hands-on with 1000+ tech skills courses.