INSPIRED BY


OTHER WRITING

Little bit of Elixir

By: skaup On: Sun 30 August 2026
In: Technical
Tags: #programming #functional-programming

It is the second last day of Blogust. And there are many ideas I have had for articles. But all of them are solid works in progress for now. So let's do a short run through of my experience with learning Elixir / Erlang now for some time now. Why, you ask? Give thyself time to learn something new and good, and cease to be whirled around. That is it. So, what is Elixir?

It is a functional programming language. Functions are first class objects. Influenced by but not really a 'pure' functional language we think of, as in Lisp, Haskell, etc. It's built on top of the BEAM VM . It's based on Erlang, which was made by Ericson in 1980s to handle telephone systems. And what always bugged me about Elixir, because I know many people who use it, is the "distributed by default" phrase people would throw around.

Hmm? Distributed by default? What does that mean? I never really got that. So as I followed some tutorials. And then something happened. In the middle it said, you have two elixir nodes, and when they are talking, it can work on two nodes on the same machine, or on two nodes on different machines in the same network! Distributed by default? Aha!

So normally I would run two nodes on the same machine to see if they worked -

Start node 1

iex --sname node1

Start node 2

iex --sname node2

Node A talks to Node B.

node1@host>net_adm:ping('node2@host')
pong # good result 

The bad result is pang, which was felt everytime it appeared on my screen.

In normal languages, since node1 and node2 are on the same machine, they can interact. Like you copying data from your local excel sheet to your own browser. But this thing was saying, look you can copy it there, and paste it on your coworkers machine also. Or your coworker can copy something, and you can automagically use it. Same thing, doesn't matter. Usually that requires you to send a teams message, wait for 3 hours for your coworker to wake up , ping them a few times asking "hey just circling back, could we get the ticket id?". Now you can tell to shove it. Aren't you happy. But how exactly does this work?

So I took another machine and wired up the config on it. Needed a few changes, but nothing too scary. And then voila.

Start Node 2 on completely different machine

iex --name node2@some-magic
1>net_adm:ping('node2@some-magic')
pong # WOW

It felt like magic. The pure joy of getting machines to talk to each other. I felt it when I was a kid and I feel it still. Again, magic. But there is a problem. I didn't understand squat about how this was happening. Like how? How are these two things talking to each other? I couldn't understand for the life of me. You can experience magic, but you can't just leave it at that.

So I decided to dig in deeper. The code I wrote earlier is actually just and example. I started out with Elixir and then switched to Erlang (the main language). The Erlang docs are just more detailed about what I wanted to explore. There were a few ways to go about it. Start two virtual machines on my computer (pretend they are two different machines) and see what it takes to get them to talk. But with docker this problem is kind of trivial. You make two nodes, get them on the same network, bada-bing bada boom. It works for sure. Ran the command to see some network traffic also, and I saw that it was resolving the ip address of host2 this time. So okay, but still is that enough?

At this point, I was struggling a bit to grasp it. Thankfully, came across Distribunomicon This thing is so awesome. It's by Fred Hebert. It explains these concepts so well. And it has an amazing quote -

See, distributed programming is like being left alone in the dark, with monsters everywhere. It's scary, you don't know what to do or what's coming at you. Bad news: distributed Erlang is still leaving you alone in the dark to fight the scary monsters. It won't do any of that kind of hard work for you. Good news: instead of being alone with nothing but pocket change and a poor sense of aim to kill the monsters, Erlang gives you a flashlight, a machete, and a pretty kick-ass mustache to feel more confident (this also applies to female readers).

Staches on! It has even better examples. He talks about how we must think of distributed communication as zombies (literally). Imagine there are two camps of zombies. And each zombie camp has sent out two members to meet the other camp's members. Bill and Zoey from camp A, Rick and Daryl from camp B set out. Each of them have walkie talkies. But each zombie can only talk to their camp. If they want to talk to the zombies from other camp, they have to relay this via the camp. That is what we have been doing. Till now we have been talking to zombies from our own camp. Now how do we talk to the zombies from the other camp?

So I did one experiment, which had two servers. The config looked something like this -

Hosts on server-01 and workstation machines

server-01:~# cat /etc/hosts

203.0.113.10    workstation workstation.public
203.0.113.20    server-01 server-01.public
workstation:# ~cat /etc/hosts
203.0.113.10    workstation workstation.public
203.0.113.20    server-01 server-01.public

Okay so they can talk to each other internally. Inspired by Distribunomicon, I will also be calling my nodes cthulu and lovecraft after eldritch monsters of HP Lovecraft. And for now -

Start Node 1 on workstation

erl -sname cthulu@workstation -setcookie howard-phillips

Start Node 2 on server-01

erl -sname lovecraft@server-01 -setcookie howard-phillips

And then to get them to talk.

(lovecraft@server-01)7> {shell, 'cthulu@workstation'} ! "That is not dead which can eternal lie".
"That is not dead which can eternal lie"

And then, a Call Of The Cthulu node -

(cthulu@workstation)6> flush().
Shell got "That is not dead which can eternal lie"
ok
(cthulu@workstation)7> {shell, 'lovecraft@server-01'} ! "And with strange aeons ...suspense".

Back to the lovecraft machine to see the whole thing

(lovecraft@server-01)8> flush().
Shell got "And with strange aeons even death may die"
ok

Works! Works pretty well. Still these two machines are effectively still kind of like talking to your own camp. I wanted to know if this would work over the internet? What if there was a mega cult, connecting groups of camps? Can you talk to zombies in the other mega cult camps? That is, could my machine talk to an Erlang node on a totally different machine over the net. Turns out it can. Spun up a server on AWS, configured some ports to ensure traffic flows -

$ erl -name lovecraft@ec2-54-261-398-873.compute-1.amazonaws.com -setcookie hp

And then on my local cthulu machine afterwords -

>net_adm:ping('lovecraft@ec2-54-261-398-873.compute-1.amazonaws.com').

pong

Saw the traffic also. The cthulu node first resolves the host. Then it connects to the EPMD (Erlang Port Mapper Daemon, usually 4369) of the remote machine, which then allows it to connect to the port where Erlang node is running (5000 in this case, which I had exposed to my IP earlier in the security group config). And so the magic is explained.

Anyways, the zombies explanation helped me a lot. Thanks to Fred Hebert. Good explanations of any concept, technical, mathematical what have you, should be something a person can hold on to. It cannot be full of jargon words. It cannot be limited to your ingroup. It is good to demand that people reach standards, sure. But the inability to explain a concept in a clear manner betrays the fact that you have not understood it. The best people in a field make something easy to grasp. Preston C Hammer calls it mind pollution. I have written about it before, it's a very useful concept. He is talking about mathematics but it is applicable everywhere -

For years I have struggled with the concept of "neighborhood," trying to find out what it means basically-i.e., to the non-topologists. Finally, I arrived at the following interpretation. The neighborhoods of an objective are the conditions which MUST be met to achieve the objective ... This conceptualization of "neighborhood" is simple, it can be explained to children, and it relates the topological concept to a much wider range of human activities.

And then the real hits -

Now, in the present state of education you will never see such a simple and non-technical discussion of neighborhood. If topology is made trivial by such interpretations, topology is trivial.

The filling of minds with technical concepts without establising their relationships to reality is a form of mind pollution.

The most important sentence there is "If topology is made trivial by such interpretations, topology is trivial." People fear they are diluting the power of something if they don't use the technical terms. Like explaining magic. How can you dare to explain magic? After all, outsiders must make an effort to understand us witches. There is some validity to that, you can't explain things every time as though you are talking to a child. Good shorthand is important, but that only works if everyone knows what is going on. Even then, Good explanations do not hide behind jargon. And if you look anywhere, there is a dearth of good explanations. We can now produce more software than ever, we can even explain it in the tech slop Orwellian terms we have come up with. But to make it truly graspable is the real trick. And as Terry Pratchett said -

"It doesn't stop being magic just because you know how it works."

Refs

1.Main Elixir docs.

2.Distribunomicon - Go read this.

3.Preston C Hammer's - Mind Pollution

4.Title is ofcourse from Alexis Rose.

5.The Terry Pratchett quote is from The Wee Free Men, incidentally also about Witches.

Post Notes

1.Thank you to my dad. He got me the full set of labs from iximiuz. It's a set of labs to learn about linux machines, containers, networking etc. It is super fun actually. But it also gives you access to some virtual machines - which were used above.

2.The Call Of The Cthulu node joke hidden in there was completely stolen from Fred Hebert. It was so funny when I first read it I cackled for 5 minutes. Arrested Development level writing for a technical book.

3.When you look up EPMD on google, you don't see anything related to Erlang. Instead you see the Rap Group Erick and Parrish Making Dollars. I propose we change the full form of EPMD to this.