Tutorial
Elixir Tutorial
A practical tutorial to get you productive with Elixir for building scalable, fault-tolerant applications. Covers functional programming, OTP, Ecto, Phoenix, and testing.
Chapters
About this tutorial
A practical tutorial to get you productive with Elixir for building scalable, fault-tolerant applications.
Who This Is For
- Developers with experience in other languages
- Those wanting to learn Elixir for backend development, real-time systems, or distributed applications
- Anyone looking for a practical, example-driven guide to functional programming
- Developers interested in the Phoenix web framework
Contents
Fundamentals
- Introduction - What is Elixir, installation, first program, IEx
- Basics - Variables, types, operators, pattern matching
- Control Flow - If, case, cond, with, loops
- Functions - Anonymous functions, named functions, guards, pipes
- Collections - Lists, tuples, maps, keyword lists, Enum module
Building Blocks
- Modules & Structs - Modules, structs, protocols, behaviours
- Error Handling - Try/rescue, with, error patterns, let it crash
Concurrency & OTP
- Processes - Processes, message passing, spawn, links, GenServer
- Mix & Projects - Mix tool, project structure, dependencies
- OTP Basics - Supervisors, applications, OTP principles
Practical Development
- Ecto & Databases - Database access, schemas, queries, changesets
- Phoenix Web Framework - Controllers, views, LiveView basics
- Testing - ExUnit, testing patterns, doctests, mocks
Mastery
- Best Practices - Idioms, patterns, conventions, performance
How to Use This Tutorial
- Read sequentially for a complete learning path (1-2 weeks)
- Jump to specific topics if you need a reference
- Type out the examples in IEx or Mix projects
- Build something after each major section
Quick Reference
Essential Commands
# Install Elixir (via asdf - recommended)
asdf install erlang latest
asdf install elixir latest
# Start interactive shell
iex
# Create a new project
mix new myproject
# Create a new Phoenix web app
mix phx.new myapp
# Run your application
mix run
# Run tests
mix test
# Format code
mix format
# Get dependencies
mix deps.get
# Start Phoenix server
mix phx.server
Hello World
# hello.exs
IO.puts("Hello, World!")
Run with: elixir hello.exs
Common Patterns
# Pattern matching
{:ok, result} = {:ok, 42}
# Pipe operator
"hello world"
|> String.upcase()
|> String.split()
# Anonymous function
add = fn a, b -> a + b end
add.(1, 2) # => 3
# Enum operations
[1, 2, 3, 4]
|> Enum.filter(&(&1 > 2))
|> Enum.map(&(&1 * 2))
# => [6, 8]
# GenServer basic structure
defmodule MyServer do
use GenServer
def start_link(initial_state) do
GenServer.start_link(__MODULE__, initial_state, name: __MODULE__)
end
def init(initial_state) do
{:ok, initial_state}
end
def handle_call(:get, _from, state) do
{:reply, state, state}
end
end
Learning Path Suggestions
Web Developer (1 week)
- Fundamentals (chapters 1-5)
- Modules & Structs (6)
- Error Handling (7)
- Mix & Projects (9)
- Ecto & Databases (11)
- Phoenix Web Framework (12)
- Testing (13)
- Build a Phoenix web application
Systems Programmer (2 weeks)
- All fundamentals (1-7)
- Deep dive into Processes (8)
- Mix & Projects (9)
- OTP Basics (10)
- Testing (13)
- Best Practices (14)
- Build a distributed system or real-time application
Complete Journey (2-3 weeks)
- Work through all chapters sequentially
- Complete exercises in each chapter
- Build 3 projects:
- CLI tool with Mix
- Real-time system with GenServer
- Full-stack web app with Phoenix
Additional Resources
- Official Elixir Documentation
- Elixir School
- Exercism Elixir Track
- Elixir Forum
- Phoenix Framework
- Hex Package Manager
- Awesome Elixir
Elixir Version
This tutorial is written for Elixir 1.16+ and Erlang/OTP 26+.
Why Elixir?
- Fault-tolerant: Built on Erlang VM (BEAM), proven for 99.9999999% uptime
- Concurrent: Lightweight processes make concurrency easy
- Scalable: Handle millions of connections on a single machine
- Productive: Beautiful syntax, powerful metaprogramming, excellent tooling
- Real-time: Perfect for chat apps, IoT, live dashboards
- Functional: Immutable data, pattern matching, no side effects