The name Erlang, attributed to Bjarne Däcker, has been presumed by those working on the telephony switches (for whom the language was designed) to be a reference to Danish mathematician and engineer Agner Krarup Erlang and a syllabic abbreviation of "Ericsson Language".789 Erlang was designed with the aim of improving the development of telephony applications.10 The initial version of Erlang was implemented in Prolog and was influenced by the programming language PLEX used in earlier Ericsson exchanges. By 1988 Erlang had proven that it was suitable for prototyping telephone exchanges, but the Prolog interpreter was far too slow. One group within Ericsson estimated that it would need to be 40 times faster to be suitable for production use. In 1992, work began on the BEAM virtual machine (VM), which compiles Erlang to C using a mix of natively compiled code and threaded code to strike a balance between performance and disk space.11 According to co-inventor Joe Armstrong, the language went from laboratory product to real applications following the collapse of the next-generation AXE telephone exchange named AXE-N in 1995. As a result, Erlang was chosen for the next Asynchronous Transfer Mode (ATM) exchange AXD.12
In February 1998, Ericsson Radio Systems banned the in-house use of Erlang for new products, citing a preference for non-proprietary languages.13 The ban caused Armstrong and others to make plans to leave Ericsson.14 In March 1998 Ericsson announced the AXD301 switch,15 containing over a million lines of Erlang and reported to achieve a high availability of nine "9"s.16 In December 1998, the implementation of Erlang was open-sourced and most of the Erlang team resigned to form a new company, Bluetail AB.17 Ericsson eventually relaxed the ban and re-hired Armstrong in 2004.18
In 2006, native symmetric multiprocessing support was added to the runtime system and VM.19
Erlang applications are built of very lightweight Erlang processes in the Erlang runtime system. Erlang processes can be seen as "living" objects (object-oriented programming), with data encapsulation and message passing, but capable of changing behavior during runtime. The Erlang runtime system provides strict process isolation between Erlang processes (this includes data and garbage collection, separated individually by each Erlang process) and transparent communication between processes (see Location transparency) on different Erlang nodes (on different hosts).
Joe Armstrong, co-inventor of Erlang, summarized the principles of processes in his PhD thesis:20
Joe Armstrong remarked in an interview with Rackspace in 2013: "If Java is 'write once, run anywhere', then Erlang is 'write once, run forever'."21
In 2014, Ericsson reported Erlang was being used in its support nodes, and in GPRS, 3G and LTE mobile networks worldwide and also by Nortel and Deutsche Telekom.22
Erlang is used in RabbitMQ. As Tim Bray, director of Web Technologies at Sun Microsystems, expressed in his keynote at O'Reilly Open Source Convention (OSCON) in July 2008:
If somebody came to me and wanted to pay me a lot of money to build a large scale message handling system that really had to be up all the time, could never afford to go down for years at a time, I would unhesitatingly choose Erlang to build it in.
Erlang is the programming language used to code WhatsApp.23
It is also the language of choice for Ejabberd – an XMPP messaging server.
Elixir is a programming language that compiles into BEAM byte code (via Erlang Abstract Format).24
Since being released as open source, Erlang has been spreading beyond telecoms, establishing itself in other vertical markets such as FinTech, gaming, healthcare, automotive, Internet of Things and blockchain. Apart from WhatsApp, there are other companies listed as Erlang's success stories, including Vocalink (a MasterCard company), Goldman Sachs, Nintendo, AdRoll, Grindr, BT Mobile, Samsung, OpenX, and SITA.2526
A factorial algorithm implemented in Erlang:
A tail recursive algorithm that produces the Fibonacci sequence:
Omitting the comments gives a much shorter program.
Quicksort in Erlang, using list comprehension:27
The above example recursively invokes the function qsort until nothing remains to be sorted. The expression [Front || Front <- Rest, Front < Pivot] is a list comprehension, meaning "Construct a list of elements Front such that Front is a member of Rest, and Front is less than Pivot." ++ is the list concatenation operator.
A comparison function can be used for more complicated structures for the sake of readability.
The following code would sort lists according to length:
A Pivot is taken from the first parameter given to qsort() and the rest of Lists is named Rest. Note that the expression
is no different in form from
(in the previous example) except for the use of a comparison function in the last part, saying "Construct a list of elements X such that X is a member of Rest, and Smaller is true", with Smaller being defined earlier as
The anonymous function is named Smaller in the parameter list of the second definition of qsort so that it can be referenced by that name within that function. It is not named in the first definition of qsort, which deals with the base case of an empty list and thus has no need of this function, let alone a name for it.
Erlang has eight primitive data types:
And three compound data types:
Two forms of syntactic sugar are provided:
Erlang has no method to define classes, although there are external libraries available.29
Erlang is designed with a mechanism that makes it easy for external processes to monitor for crashes (or hardware failures), rather than an in-process mechanism like exception handling used in many other programming languages. Crashes are reported like other messages, which is the only way processes can communicate with each other,30 and subprocesses can be spawned cheaply (see below). The "let it crash" philosophy prefers that a process be completely restarted rather than trying to recover from a serious failure.31 Though it still requires handling of errors, this philosophy results in less code devoted to defensive programming where error-handling code is highly contextual and specific.32
A typical Erlang application is written in the form of a supervisor tree. This architecture is based on a hierarchy of processes in which the top level process is known as a "supervisor". The supervisor then spawns multiple child processes that act either as workers or more, lower level supervisors. Such hierarchies can exist to arbitrary depths and have proven to provide a highly scalable and fault-tolerant environment within which application functionality can be implemented.
Within a supervisor tree, all supervisor processes are responsible for managing the lifecycle of their child processes, and this includes handling situations in which those child processes crash. Any process can become a supervisor by first spawning a child process, then calling erlang:monitor/2 on that process. If the monitored process then crashes, the supervisor will receive a message containing a tuple whose first member is the atom 'DOWN'. The supervisor is responsible firstly for listening for such messages and for taking the appropriate action to correct the error condition.
Erlang's main strength is support for concurrency. It has a small but powerful set of primitives to create processes and communicate among them. Erlang is conceptually similar to the language occam, though it recasts the ideas of communicating sequential processes (CSP) in a functional framework and uses asynchronous message passing.33 Processes are the primary means to structure an Erlang application. They are neither operating system processes nor threads, but lightweight processes that are scheduled by BEAM. Like operating system processes (but unlike operating system threads), they share no state with each other. The estimated minimal overhead for each is 300 words.34 Thus, many processes can be created without degrading performance. In 2005, a benchmark with 20 million processes was successfully performed with 64-bit Erlang on a machine with 16 GB random-access memory (RAM; total 800 bytes/process).35 Erlang has supported symmetric multiprocessing since release R11B of May 2006.
While threads need external library support in most languages, Erlang provides language-level features to create and manage processes with the goal of simplifying concurrent programming. Though all concurrency is explicit in Erlang, processes communicate using message passing instead of shared variables, which removes the need for explicit locks (a locking scheme is still used internally by the VM).36
Inter-process communication works via a shared-nothing asynchronous message passing system: every process has a "mailbox", a queue of messages that have been sent by other processes and not yet consumed. A process uses the receive primitive to retrieve messages that match desired patterns. A message-handling routine tests messages in turn against each pattern, until one of them matches. When the message is consumed and removed from the mailbox the process resumes execution. A message may comprise any Erlang structure, including primitives (integers, floats, characters, atoms), tuples, lists, and functions.
The code example below shows the built-in support for distributed processes:
As the example shows, processes may be created on remote nodes, and communication with them is transparent in the sense that communication with remote processes works exactly as communication with local processes.
Concurrency supports the primary method of error-handling in Erlang. When a process crashes, it neatly exits and sends a message to the controlling process which can then take action, such as starting a new process that takes over the old process's task.3738
The official reference implementation of Erlang uses BEAM.39 BEAM is included in the official distribution of Erlang, called Erlang/OTP. BEAM executes bytecode which is converted to threaded code at load time. It also includes a native code compiler on most platforms, developed by the High Performance Erlang Project (HiPE) at Uppsala University. Since October 2001 the HiPE system is fully integrated in Ericsson's Open Source Erlang/OTP system.40 It also supports interpreting, directly from source code via abstract syntax tree, via script as of R11B-5 release of Erlang.
Erlang supports language-level Dynamic Software Updating. To implement this, code is loaded and managed as "module" units; the module is a compilation unit. The system can keep two versions of a module in memory at the same time, and processes can concurrently run code from each. The versions are referred to as the "new" and the "old" version. A process will not move into the new version until it makes an external call to its module.
An example of the mechanism of hot code loading:
For the second version, we add the possibility to reset the count to zero.
Only when receiving a message consisting of the atom code_switch will the loop execute an external call to codeswitch/1 (?MODULE is a preprocessor macro for the current module). If there is a new version of the counter module in memory, then its codeswitch/1 function will be called. The practice of having a specific entry-point into a new version allows the programmer to transform state to what is needed in the newer version. In the example, the state is kept as an integer.
In practice, systems are built up using design principles from the Open Telecom Platform, which leads to more code upgradable designs. Successful hot code loading is exacting. Code must be written with care to make use of Erlang's facilities.
In 1998, Ericsson released Erlang as free and open-source software to ensure its independence from a single vendor and to increase awareness of the language. Erlang, together with libraries and the real-time distributed database Mnesia, forms the OTP collection of libraries. Ericsson and a few other companies support Erlang commercially.
Since the open source release, Erlang has been used by several firms worldwide, including Nortel and Deutsche Telekom.41 Although Erlang was designed to fill a niche and has remained an obscure language for most of its existence, its popularity is growing due to demand for concurrent services.4243 Erlang has found some use in fielding massively multiplayer online role-playing game (MMORPG) servers.44
"Erlang – Introduction". erlang.org. Archived from the original on 8 September 2019. Retrieved 6 February 2017. https://web.archive.org/web/20190908105859/http://erlang.org/doc/system_architecture_intro/sys_arch_intro.html#id58791 ↩
Armstrong, Joe; Däcker, Bjarne; Lindgren, Thomas; Millroth, Håkan. "Open-source Erlang – White Paper". Archived from the original on 25 October 2011. Retrieved 31 July 2011. https://web.archive.org/web/20111025022940/http://ftp.sunet.se/pub/lang/erlang/white_paper.html ↩
Hitchhiker’s Tour of the BEAM – Robert Virding http://www.erlang-factory.com/upload/presentations/708/HitchhikersTouroftheBEAM.pdf http://www.erlang-factory.com/upload/presentations/708/HitchhikersTouroftheBEAM.pdf ↩
Armstrong, Joe (2007). History of Erlang. HOPL III: Proceedings of the third ACM SIGPLAN conference on History of programming languages. ISBN 978-1-59593-766-7. 978-1-59593-766-7 ↩
"How tech giants spread open source programming love - CIO.com". 8 January 2016. Archived from the original on 22 February 2019. Retrieved 5 September 2016. https://web.archive.org/web/20190222070551/https://www.cio.com/article/3020454/open-source-tools/how-tech-giants-spread-open-source-programming-love.html ↩
"Erlang/OTP Released as Open Source, 1998-12-08". Archived from the original on 9 October 1999. https://web.archive.org/web/19991009002753/http://www.erlang.se/onlinenews/ErlangOTPos.shtml ↩
"Erlang, the mathematician?". February 1999. http://www.erlang.org/pipermail/erlang-questions/1999-February/000098.html ↩
"Free Online Dictionary of Computing: Erlang". https://foldoc.org/Erlang ↩
"History of Erlang". Erlang.org. http://erlang.org/course/history.html ↩
Armstrong, Joe (August 1997). "The development of Erlang". Proceedings of the second ACM SIGPLAN international conference on Functional programming. Vol. 32. pp. 196–203. doi:10.1145/258948.258967. ISBN 0897919181. S2CID 6821037. {{cite book}}: |journal= ignored (help) 0897919181 ↩
Däcker, Bjarne (October 2000). Concurrent Functional Programming for Telecommunications: A Case Study of Technology Introduction (PDF) (Thesis). Royal Institute of Technology. p. 37. https://cogsys.uni-bamberg.de/team/schmid/uoshp/lehreuos/fp01-www/fp-referate/erlang/bjarnelic.pdf#page=45 ↩
"question about Erlang's future". 6 July 2010. http://erlang.org/pipermail/erlang-questions/2006-July/021368.html ↩
"Concurrency Oriented Programming in Erlang" (PDF). 9 November 2002. http://www.rabbitmq.com/resources/armstrong.pdf ↩
Armstrong, Joe (20 November 2003). Making reliable distributed systems in the presence of software errors (DTech thesis). Stockholm, Sweden: The Royal Institute of Technology. ↩
McGreggor, Duncan (26 March 2013). Rackspace takes a look at the Erlang programming language for distributed computing (Video). Rackspace Studios, SFO. Archived from the original on 11 December 2021. Retrieved 24 April 2019. https://www.youtube.com/watch?v=u41GEwIq2mE&t=3m59s ↩
"Ericsson". Ericsson.com. 4 December 2014. Retrieved 7 April 2018. http://www.ericsson.com/news/141204-inside-erlang-creator-joe-armstrong-tells-his-story_244099435_c ↩
"Inside Erlang, The Rare Programming Language Behind WhatsApp's Success". fastcompany.com. 21 February 2014. Retrieved 12 November 2019. https://www.fastcompany.com/3026758/inside-erlang-the-rare-programming-language-behind-whatsapps-success ↩
"Erlang/Elixir Syntax: A Crash Course". elixir-lang.github.com. Retrieved 10 October 2022. https://elixir-lang.org/crash-course.html ↩
"Which companies are using Erlang, and why? #MyTopdogStatus". erlang-solutions.com. 11 September 2019. Retrieved 15 March 2020. https://www.erlang-solutions.com/blog/which-companies-are-using-erlang-and-why-mytopdogstatus.html ↩
"Which new companies are using Erlang and Elixir? #MyTopdogStatus". erlang-solutions.com. 2 March 2020. Retrieved 24 June 2020. https://www.erlang-solutions.com/blog/which-new-companies-are-using-erlang-and-elixir-mytopdogstatus.html ↩
"Erlang – List Comprehensions". erlang.org. http://erlang.org/doc/programming_examples/list_comprehensions.html ↩
"String and Character Literals". Retrieved 2 May 2015. http://erlang.org/doc/apps/stdlib/unicode_usage.html#string-and-character-literals ↩
"ect – Erlang Class Transformation – add object-oriented programming to Erlang – Google Project Hosting". Retrieved 2 May 2015. https://code.google.com/p/ect/ ↩
Verraes, Mathias (9 December 2014). "Let It Crash". Mathias Verraes' Blog. Retrieved 10 February 2021. https://verraes.net/2014/12/erlang-let-it-crash/ ↩
"Reactive Design Patterns —". www.reactivedesignpatterns.com. Retrieved 10 February 2021. https://www.reactivedesignpatterns.com/patterns/let-it-crash.html ↩
Armstrong, Joe (September 2010). "Erlang". Communications of the ACM. 53 (9): 68–75. doi:10.1145/1810891.1810910. Erlang is conceptually similar to the occam programming language, though it recasts the ideas of CSP in a functional framework and uses asynchronous message passing. /wiki/Joe_Armstrong_(programmer) ↩
"Erlang Efficiency Guide – Processes". Archived from the original on 27 February 2015. https://web.archive.org/web/20150227174813/http://www.erlang.org/doc/efficiency_guide/processes.html ↩
Wiger, Ulf (14 November 2005). "Stress-testing erlang". comp.lang.functional.misc. Retrieved 25 August 2006. https://groups.google.com/group/comp.lang.functional/msg/33b7a62afb727a4f?dmode=source ↩
"Lock-free message queue". Archived from the original on 24 December 2013. Retrieved 23 December 2013. https://web.archive.org/web/20131224104549/http://erlang.2086793.n4.nabble.com/Lock-free-message-queue-td2550221.html ↩
Armstrong, Joe. "Erlang robustness". Archived from the original on 23 April 2015. Retrieved 15 July 2010. https://web.archive.org/web/20150423182840/http://www.erlang.org/doc/getting_started/robustness.html ↩
"Erlang Supervision principles". Archived from the original on 6 February 2015. Retrieved 15 July 2010. https://web.archive.org/web/20150206050600/http://www.erlang.org/doc/design_principles/sup_princ.html ↩
"Erlang – Compilation and Code Loading". erlang.org. Retrieved 21 December 2017. http://erlang.org/doc/reference_manual/code_loading.html#id90080 ↩
"High Performance Erlang". Retrieved 26 March 2011. http://www.it.uu.se/research/group/hipe/ ↩
"Who uses Erlang for product development?". Frequently asked questions about Erlang. Retrieved 16 July 2007. The largest user of Erlang is (surprise!) Ericsson. Ericsson use it to write software used in telecommunications systems. Many dozens of projects have used it, a particularly large one is the extremely scalable AXD301 ATM switch. Other commercial users listed as part of the FAQ include: Nortel, Deutsche Flugsicherung (the German national air traffic control organisation), and T-Mobile. http://erlang.org/faq/introduction.html#idp32141008 ↩
"Programming Erlang". Retrieved 13 December 2008. Virtually all language use shared state concurrency. This is very difficult and leads to terrible problems when you handle failure and scale up the system...Some pretty fast-moving startups in the financial world have latched onto Erlang; for example, the Swedish www.kreditor.se. http://www.ddj.com/linux-open-source/201001928?cid=RSSfeed_DDJ_OpenSource ↩
"Erlang, the next Java". Archived from the original on 11 October 2007. Retrieved 8 October 2008. I do not believe that other languages can catch up with Erlang anytime soon. It will be easy for them to add language features to be like Erlang. It will take a long time for them to build such a high-quality VM and the mature libraries for concurrency and reliability. So, Erlang is poised for success. If you want to build a multicore application in the next few years, you should look at Erlang. https://web.archive.org/web/20071011065959/http://cincomsmalltalk.com/userblogs/ralph/blogView?showComments=true&entry=3364027251 ↩
Clarke, Gavin (5 February 2011). "Battlestar Galactica vets needed for online roleplay". Music and Media. The Reg. Retrieved 8 February 2011. https://www.theregister.co.uk/2011/02/05/battlestar_galactica_mmp/ ↩