Under the hood, every blockchain has a mix of different mechanisms to make it work, depending on what programmers believe is the right way to tackle problems. There’s usually no right or wrong solution—there are only better ones. Even forks—carbon copies of existing blockchains—will differ in some ways as developers pursue what they perceive are better ways to deal with scale, speed, and other aspects of distributed systems.
At the very core of blockchains is the engineers’ programming language of choice. Bitcoin was written in C++; Ethereum was written in Go, C++, and now Rust. To build smart contracts on Ethereum, there’s Solidity. Most would have heard of these languages; even casual enthusiasts would have encountered these at one point or another in their daily reads.
Yet there is one language that has been making its way into the discussion. Erlang, despite not being a household name, was actually created 33 years ago. As a matter of fact, it’s an active part of the infrastructure that powers the Internet we use today. Despite not having the same popularity as other more commonly known programming languages, Tobias Lindahl asserts that Erlang is the perfect programming language—and disciplinary foundation, for building a blockchain.
Lindahl, a 20-year Erlang veteran with a Masters of Science in Engineering Physics, spent several years doing research and work on virtual machines (VM). He’s currently part of the star-studded developer team of æternity, alongside other programming legends—with one of Erlang’s co-creators, Robert Virding among them.
From Scratch: Engineering a Better Blockchain
According to Lindahl, Erlang and blockchain have so many commonalities that it only made sense that it be used for the core blockchain protocol when reimagined from scratch.
“Since blockchains are so heavily reliant on communication, it would have been natural to have it in Erlang in the first place,” Lindahl explained. “The language was built for building distributed systems in telecom. So, communication between nodes is very easy to implement in Erlang.”
He adds that apart from being developed for scalable global networks of nodes, the way programmers think of problems in Erlang gives them a significant advantage when tackling problems in blockchain.
“The immutability in the Erlang language is similar to the immutability of blockchains. Once something has entered the chain, it will never change. This is very similar to how you think about Erlang problems,” he said.
Why Erlang is Perfect for Building a Blockchain
It is easy to claim that one solution is better than the other—in the intensely competitive blockchain space, such claims are far too common. To support his stance, Lindahl illustrates why he believes Erlang is the best programming language for building a blockchain.
“With Erlang, you have immutability of data, so you have no destructive updates. It makes it easier to reason about programs, and even prove some things about them. It also makes it easier to test programs,” he said. He added that Erlang enables not only the massive and rapid distribution of transaction data—it allows multiple processes to run simultaneously without bumping into each other.
“It’s very easy to have a separation of concerns with Erlang. When a process is dealing with something, it doesn’t need to worry about any other process coming in and changing the state of its data. For me this is the main benefit. You have concurrency of course. You can have thousands of processes running at the same time without affecting each other—except when you explicitly want them to communicate.”
As a result, Lindahl and the developer teams at æternity are able to deploy important features seamlessly, and the blockchain is able to handle volume better. The first protocol upgrade of the æternity protocol (hard fork) proved Tobias’ claims—it was executed without a single issue.
“We use the Noise protocol for communication between nodes. It’s easy to set up separate node connections to other nodes without them interfering with each other. That’s another built-in feature of Erlang—it’s easy to manage separate connections without having to deal with semaphores or critical sections of programs,” he said.
“Implementing Noise-like protocols is much more straightforward with Erlang. It’s easy to handle the connections between different nodes because you have this separation of concerns. You can just assign one Erlang process to handle one connection to another node and this can go on and on. And you know that no other processes will interfere with this. So you don’t have to worry about the other connections.” ]
He added that Erlang enables a very resilient system, one that can scale as needed.
“In case a connection dies, another process, called a supervisor, will be notified that his connection died and you can reestablish it,” explained Lindahl. “Erlang has a lot of built-ins for dealing with error recovery and fault tolerance. So, it’s easy to have many Erlang processes running. You can more or less scale infinitely, or to be more accurate, you can scale as far as you need through Erlang. You don’t need to worry about scale and that’s one of the biggest issues in the blockchain industry today.”
Why Didn’t Others Use Erlang For Blockchain-Building?
Lindahl’s arguments are quite convincing, which leads to the question of why blockchain technology wasn’t built on Erlang from the start, and why many well-known blockchain platforms didn’t incorporate Erlang in their own solutions. “The Erlang community isn’t that big. There aren’t that many people using Erlang.”
“I don’t think there’s a fundamental reason why it wasn’t used from the beginning. Obviously, Erlang isn’t best-suited for everything. And perhaps it was the Proof-of-Work (PoW) that was the problem. You wouldn’t implement that in Erlang. That would be totally useless. It would be very slow compared to having a proper C solution or something similar.”
Blockchain: High or Low-Level?
Ultimately, Lindahl says that the distinction between high and low-level programming determines the complexity of how you build a blockchain, which subsequently affects how far you can stretch the possibilities of a platform. In the blockchain industry, this is a game-changer: it can spell a platform’s global scale success over other networks.
“I think with the high-level nature of Erlang, the way you think about problems is that you abstract. You abstract away because you have the high-level context,” Lindahl added. In low-level programming, the programmer gives instructions for every single action. In high-level programming, the programmer gives an objective—and the machine knows all the individual actions necessary to achieve that goal.
For those who are interested in learning more, Lindahl recommends scouring through æternity’s Documentation Hub. Their Github repository is also a good starting point. Apart from these, a community-backed team called Dacade also created a tutorial for æternity Development (from which successful finishers get $100 in AE tokens). And for those who seriously want to get in on the action, they have an upcoming conference, æternity Universe, where developers and entrepreneurs can get answers to their questions straight from æternity’s developers and founders.