Why Erlang

Why Erlang

Have you ever had to program from zero sockets in order to start your own server? Are you passionate about networking and communication protocols such as stop-and-wait, Go-Back-N, Selective Repeat, TCP/UDP? Have you ever had to create high-performance computing and high availability systems from scratch? Sorry, this article is not for beginners.

I wrote my first socket code around 1997, a simple broadcast server that basically works very similar to a chat. It doesn’t sound too complicated, doesn’t it? Well, as it usually happens, nothing was as simple as it looked, especially if the code was written in C++, and on top of that, the internet was not as omnipresent as it is today (Google didn’t exist). Basically, to create a communication server it is required to dominate concepts related to programming and networks such as threads, locks, connection pool management, data packets, understanding how they work, TCP and UDP. The following link that I’m sharing with you has a repo on GitHub which contains cross-platform raw sockets that I wrote in the 90’s, in case you are interesting in delving deeper into these concepts https://github.com/kriskoin/rawsockets.

Currently, all this coding can be easier with languages such as JavaScript. The repository mentioned before, was written in C++ and can be summarized on few lines of code which makes the implementation of client-server applications easier, abstracting the details from the network layer https://github.com/kriskoin/dummy_websocket_server. Despite JavaScript making things easier for you, your application will have the same issues and bottlenecks. The reason for this, is that both codes are written in general purpose programming languages. In this kind of development, it is required administrative shared resource (shared memory) which has an impact on the process performance, besides, processes often belong to the operating system, which somehow limits its administration inside the development environment.

From my perspective as a programmer, what caught my eye about Erlang? 90% of my projects have required high performance, but with interpreted languages you normally don’t have the best time of response. Even so, compiled codes have also its cons such as portability, this meaning that both the compiled code as well as the interpreted code have its pros and cons. Does it exist something intermediate? Oh, well…Surprise! Erlang provides a compiled pseudo-language that runs on a set of pseudo-instructions of a distributed virtual machine.

It is owned by Ericsson, and was designed by Joe Armstrong, with the objective of it being concurrent and of high availability on telephony environments. Basically, Joe and his team of researchers designed a ‘telephonic algebra.’ Yes. They used math to solve a networking problem. This algebra is capable of solving all problems related to availability and high performance on data transmission networking. It does not exist a consensus about the type of language that it is, given its characteristics of both functional and declarative language.

image took from : https://www.youtube.com/watch?v=4elY_RuyBhQ

image took from : https://www.youtube.com/watch?v=4elY_RuyBhQ

Next, I will list some of the most relevant characteristics that I have witnessed myself, as follows:

  • Let it crash:   High availability can be achieved when the use case “What should I do when this process is down?” is implemented.
  • Hot code swapping: It allows to update the code while is ‘hot’, without having to slow/shutting down the process. This mechanism facilitates the implementation of unstoppable systems.
  • Designed for building massively concurrent: According to https://99firms.com/blog/whatsapp-statistics/ WhatsApp (uses Erlang) processes 29 million messages per minute/483,333 per second.
  • Erlang processes are lightweight and belong to their own language, not to the operating system.
  • Immutable variables.
  • Pattern matching.
  • Garbage Collector.

If you need to create an environment where high performance and high availability is required, I recommend you to use Erlang. Here, you will find a little example on how a socket server is made using Erlang https://github.com/kriskoin/erlang-sockets


To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics