Elixir Distribution, ELI5

Let’s form cluster locally

Start three Nodes
iex(foo@pop-os)1> Node.list()
List Nodes in the Cluster
iex(foo@pop-os)2> Node.ping(:"bar@pop-os")
Let’s ping another Node
iex(foo@pop-os)3> Node.list()
List the foo’s Nodes again
List the bar’s Nodes
iex(baz@pop-os)1> Node.list()
iex(baz@pop-os)2> Node.ping(:"foo@pop-os")
iex(baz@pop-os)3> Node.list()
List baz’s known Nodes
Let’s check all the Nodes

A quiet hero

epmd -names
Query epmd

Getting serious

IP Address of one computer
IP address of the other computer
> iex --name foo@
Start foo on the first computer
> iex --name bar@
Start bar on the other computer
iex(bar@> Node.ping(:"foo@")
Connect Nodes — first attempt
iex(bar@> Node.list()
List known Nodes
A log message
iex --name foo@ --erl "-setcookie for_fun"
Start a named Node with Cookie
iex --name bar@ --erl "-setcookie for_fun"
Start another Node with the same Cookie
iex(bar@> Node.ping(:"foo@")
Connect Nodes — second attempt
iex(bar@> Node.list()
List known foo’s Nodes
iex(foo@> Node.list()
Bar’s known Nodes
epmd on foo
epmd on bar


  1. There are two strategies to start BEAM Node in a Distributed mode:
    * With a “short name” (--sname option) that is sufficient to start Nodes on the same machine
    * With a “fully qualified name” (--name option) that has to include the location of the Node, eg. the IP address of the machine it is hosted on
  2. For the Nodes to connect, they have to share the same Cookie (via --erl "-setcookie <cookie>")
  3. When starting BEAM in a Distributed Node, additional process — EPMD- is started, which tracks the ports for each registered Node.
    In fact, when the cross-machine communication is established, this is a very first attempt between Nodes — when one Node tries to connect to the other, it will check with EPMD first, and a random port, upon successful connection will be allocated.
    In fact, port management will be very important when deploying applications eg. in AWS’ environment, so we will need to make sure proper ports are configured, otherwise — the Nodes won’t be able to connect.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store