ScriptsApr 12, 2026·1 min read

Elixir — Dynamic Functional Language for Scalable Apps

Elixir is a dynamic, functional language for building scalable and maintainable applications. Runs on the battle-tested Erlang virtual machine (BEAM) with the same fault-tolerant, distributed, soft real-time properties. The language behind Phoenix framework and LiveView.

SC
Script Depot · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

# Install via asdf or direct
brew install elixir                         # macOS
sudo apt install elixir                     # Debian/Ubuntu

elixir --version
iex                                          # Interactive shell

Hello world:

# hello.exs
defmodule Greeter do
  def hello(name), do: "Hello, #{name}"

  def top_users(users) do
    users
    |> Enum.sort_by(&(&1.score), :desc)
    |> Enum.take(3)
  end
end

users = [
  %{name: "Alice", score: 95},
  %{name: "Bob",   score: 87},
  %{name: "Carol", score: 91},
]

Greeter.top_users(users) |> IO.inspect()

Mix (project build tool):

mix new my_app
cd my_app
mix deps.get
mix test
mix run -e "MyApp.hello()"

# Phoenix web framework
mix archive.install hex phx_new
mix phx.new my_web --database postgres
cd my_web
mix ecto.create
mix phx.server
Intro

Elixir is a dynamic, functional language for building scalable and maintainable applications. Created by Jose Valim in 2011, Elixir runs on the Erlang virtual machine (BEAM) and inherits all the fault-tolerance, distribution, and soft real-time properties that made Erlang famous at Ericsson for telecom. Elixir wraps that power in a modern, Ruby-inspired syntax. Powers WhatsApp-scale chat systems, Discord voice, Pinterest notifications, and Phoenix LiveView real-time web apps.

What Elixir Does

  • Functional — immutable data, pattern matching, pipe operator
  • Actor model — lightweight processes (millions per node)
  • OTP — supervision trees, GenServer, Agent, Task
  • Fault tolerance — let it crash philosophy, supervised restarts
  • Distribution — connect nodes across machines
  • Hot code reload — swap code without downtime
  • Phoenix — high-performance web framework
  • LiveView — server-rendered real-time UI without JS
  • Ecto — database abstraction with changesets and query DSL
  • Mix — build tool, tasks, compiler, tests
  • ExUnit — built-in test framework

Architecture

Elixir code compiles to Erlang bytecode and runs on BEAM VM. Each process is isolated (own heap), messages are passed by copy, and the scheduler is preemptive across processes. Supervisors restart failed children per a declared strategy. Cluster formation via Erlang Distribution Protocol.

Self-Hosting

Language toolchain.

Key Features

  • BEAM VM (Erlang runtime)
  • Millions of lightweight processes
  • Actor model messaging
  • OTP supervision trees
  • Hot code upgrade
  • Distributed clustering
  • Pattern matching
  • Pipe operator for data flow
  • Phoenix web framework
  • LiveView for real-time UIs
  • Mix build tool

Comparison

Language Runtime Concurrency Fault Tolerance
Elixir BEAM Actor model Supervision
Erlang BEAM Actor model Supervision
Go Native Goroutines Manual
Scala (Akka) JVM Actor model Supervision
Rust Native Async + threads Result types
Java JVM Threads + Loom Exceptions

常见问题 FAQ

Q: Elixir vs Erlang? A: 同一 VM (BEAM),语法不同。Elixir 语法更现代 (Ruby-ish),macros 更强,Mix 工具更友好。Erlang 语法更贴近 Prolog,对老玩家习惯。新项目推荐 Elixir。

Q: LiveView 是什么? A: Phoenix 的特色功能——服务端渲染 UI,通过 WebSocket 推送 diff 到浏览器。零 JS 代码做实时 UI,和 React 级体验接近但无前后端分离。

Q: 适合什么场景? A: 实时应用、聊天、游戏服务器、IoT 后端、高并发 API、需要 fault tolerance 的系统。WhatsApp、Discord、Pinterest 都在用。

来源与致谢 Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets