Elixir
- Pronunciation
- ih-LIK-ser
In short
Elixir is a dynamic, functional language that runs on the Erlang virtual machine and is known for building fault-tolerant, highly concurrent systems.
What is Elixir?
Elixir is a general-purpose, functional programming language created by José Valim and first released in 2012, with version 1.0 arriving in 2014. It runs on the BEAM, the virtual machine built for Erlang, so it inherits decades of engineering for systems that must stay up for years. Elixir adds a friendlier syntax, macros for metaprogramming, and modern tooling such as the mix build tool and the Hex package manager.
Elixir code runs in lightweight processes, tiny isolated units managed by the BEAM rather than by the operating system, and a single server can run millions of them. Processes share no memory and communicate only by sending messages, while supervisors watch over them and restart any that crash, an approach known as "let it crash". Elixir is dynamically typed, and recent versions have begun adding a gradual type checker to the compiler.
Data in Elixir is immutable, and the pipe operator |> passes the result of one function as the first argument of the next, so a transformation reads from top to bottom like a recipe. Elixir is used for web applications and APIs, often with the Phoenix framework, and for real-time chat and notification systems, embedded devices and data pipelines.
Elixir is closely related to Erlang, and the two are often confused. Both compile to bytecode for the same BEAM virtual machine and can call each other's code directly, so Elixir projects use Erlang's OTP libraries for supervision and distribution. The difference is mostly on the surface: Elixir has a Ruby-inspired syntax, macros and newer tooling, while Erlang has a Prolog-inspired syntax and a longer history in telecom.
Key takeaways
- Elixir runs on the BEAM, the Erlang virtual machine, and interoperates with Erlang code.
- Lightweight processes and message passing make massive concurrency practical.
- Supervisors restart failed processes, which helps systems recover automatically.
- Data is immutable, and the pipe operator
|>chains transformations. - It is popular for real-time web applications, often with the Phoenix framework.
Example
# Pipe a string through a series of transformations
"the quick brown fox jumps over the lazy dog"
|> String.split()
|> Enum.map(&String.length/1)
|> Enum.sum()
|> IO.puts() # 35
# Spawn a lightweight process and send it a message
pid = spawn(fn ->
receive do
{:greet, name} -> IO.puts("Hello, #{name}!")
end
end)
send(pid, {:greet, "Ada"})Readers ask
What is the difference between Elixir and Erlang?
Both run on the same BEAM virtual machine and share the OTP libraries, so they have the same concurrency and fault-tolerance model. Elixir offers a Ruby-like syntax, macros and modern tooling, while Erlang is the older language with its own Prolog-inspired syntax.
What is Elixir used for?
Elixir is used for web backends, real-time features like chat and live dashboards, messaging systems, embedded devices and data processing pipelines, anywhere high concurrency and uptime matter.
Is Elixir statically typed?
Elixir is dynamically typed, but since 2024 its compiler has been gaining a gradual, set-theoretic type system that catches some type errors without requiring annotations. Developers can also write typespecs and run separate analysis tools.
See also
- ErlangProgramming Languages, p. 10Erlang is a functional language created at Ericsson for telecom switches, designed for massive concurrency, fault tolerance and systems that must keep running.
- Functional ProgrammingProgramming Fundamentals, p. 22Functional programming is a style of building software from pure functions that avoid changing shared data, making code more predictable and easier to test.
- ConcurrencyProgramming Fundamentals, p. 12Concurrency is a program's ability to make progress on several tasks in overlapping time periods, such as serving many users at once rather than one at a time.
- ImmutabilityProgramming Fundamentals, p. 27Immutability means a value cannot be changed after it is created, so every update produces a new value instead of modifying the original in place.
- Fault ToleranceSoftware Architecture, p. 20Fault tolerance is the ability of a system to keep working correctly, perhaps at reduced capacity, when some of its hardware or software components fail.
- RubyProgramming Languages, p. 28Ruby is a dynamic, object-oriented programming language designed for developer happiness, best known for readable syntax and the Ruby on Rails web framework.
Spotted a mistake or something missing on this page?Suggest an edit