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.

Tutorial·Difficulty: Intermediate·14 chapters·Updated Apr 19, 2026

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

  1. Introduction - What is Elixir, installation, first program, IEx
  2. Basics - Variables, types, operators, pattern matching
  3. Control Flow - If, case, cond, with, loops
  4. Functions - Anonymous functions, named functions, guards, pipes
  5. Collections - Lists, tuples, maps, keyword lists, Enum module

Building Blocks

  1. Modules & Structs - Modules, structs, protocols, behaviours
  2. Error Handling - Try/rescue, with, error patterns, let it crash

Concurrency & OTP

  1. Processes - Processes, message passing, spawn, links, GenServer
  2. Mix & Projects - Mix tool, project structure, dependencies
  3. OTP Basics - Supervisors, applications, OTP principles

Practical Development

  1. Ecto & Databases - Database access, schemas, queries, changesets
  2. Phoenix Web Framework - Controllers, views, LiveView basics
  3. Testing - ExUnit, testing patterns, doctests, mocks

Mastery

  1. Best Practices - Idioms, patterns, conventions, performance

How to Use This Tutorial

  1. Read sequentially for a complete learning path (1-2 weeks)
  2. Jump to specific topics if you need a reference
  3. Type out the examples in IEx or Mix projects
  4. 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)

  1. Fundamentals (chapters 1-5)
  2. Modules & Structs (6)
  3. Error Handling (7)
  4. Mix & Projects (9)
  5. Ecto & Databases (11)
  6. Phoenix Web Framework (12)
  7. Testing (13)
  8. Build a Phoenix web application

Systems Programmer (2 weeks)

  1. All fundamentals (1-7)
  2. Deep dive into Processes (8)
  3. Mix & Projects (9)
  4. OTP Basics (10)
  5. Testing (13)
  6. Best Practices (14)
  7. Build a distributed system or real-time application

Complete Journey (2-3 weeks)

  1. Work through all chapters sequentially
  2. Complete exercises in each chapter
  3. Build 3 projects:
    • CLI tool with Mix
    • Real-time system with GenServer
    • Full-stack web app with Phoenix

Additional Resources

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