Chapter 30 — The Migration Roadmap
An 8-week, step-by-step plan from “I know Erlang” to “I ship in the Elixir ecosystem.” Each phase has concrete actions, artifacts, and an exit checklist. Adjust the pace — keep the order.
Phase 0 — Environment (Day 1)
Do:
- Install Elixir via your version manager (mise/asdf): target Elixir 1.20.x (gradual typing, Ch 07) on a current OTP release. The minimum for this book is OTP 26+, but new projects should start on the latest stable line (OTP 28/29 as of writing) — check erlang.org and the Elixir “Compatibility and deprecations” page for the pairing.
- Install Livebook:
brew install livebook(ormix escript.install hex livebook). - Keep a scratch notebook open from day one — every chapter’s iex blocks paste directly into cells.
Exit when: elixir --version shows 1.20+ on your chosen OTP, Livebook opens.
Verify Before You Trust
elixir --version
#=> Erlang/OTP 28 [erts-…] … [64-bit] …
#=> Elixir 1.20.x (compiled with Erlang/OTP 28)
Pin the pair, not just the Elixir version — most first-day failures are
an Elixir binary compiled against a different OTP than the one on $PATH.
Phase 1 — Syntax (Week 1)
Goal: read Elixir as fast as you read Erlang.
- Work through Ch 02 tables; translate one of your own
.erlmodules by hand. - Drill the differences: strings-are-binaries,
fnvsfun,@attrvs-define, structs vs records. - Practice pipes until nested calls feel wrong: rewrite three list pipelines
with
|>+Enum. - Read Ch 25 (pattern matching deep dive) and redo this phase’s drills with its rules in mind — pins instead of Erlang’s auto-compare, map subset matching, binary segments. Week 1 is where Erlang reflexes cost you most; the deep dive names each trap before it bites.
Exit checklist:
- Translated module compiles under
mix compile - Can pattern-match a struct in a function head
- Can explain what
^(pin) changes versus a plain variable match (Ch 25) - Know when
"abc"is a binary vs~c"abc"a charlist
The Translation Drill, Side by Side
Pick a module you know cold — translation exposes the real differences:
%% totals.erl
total([]) -> 0;
total([{_, Price} | Rest]) -> Price + total(Rest).
defmodule Totals do
def total([]), do: 0
def total([{_, price} | rest]), do: price + total(rest)
end
Identical shape. Then rewrite it as Enum.reduce/3 and notice the
recursive clause pair was the reduce all along — that click is Week 1’s
real goal.
Phase 2 — Tooling (Week 2)
Goal: Mix replaces rebar3 muscle memory (Ch 03).
mix new drill --sup; add a GenServer child — after skimming Ch 23, so the catch-allhandle_info, call timeouts, andterminatetruth table are right from day one; write ExUnit tests.- Add a Hex dep, call an Erlang module (
:lists,:ets) from Elixir code. - Run
mix format,mix docs(add ex_doc), buildmix release(Ch 09). - Turn on the type checker: read every warning from
mix compile(Ch 07 §7.3’styping_demoscratch project is the sandbox). - Kill your own GenServer mid-request and watch the supervisor rebuild it
(Ch 22–24) — restart budgets,
:rest_for_oneordering, and crash reports read in dev cost nothing; in prod they cost incidents.
Exit checklist:
- Supervised app with tests passes
mix test - Release boots:
_build/prod/rel/drill/bin/drill start - Fixed at least two gradual-typing warnings
- Killed and restarted a supervised child on purpose, then explained the crash report line by line (Ch 24)
Read the Build Like a Profiler
mix xref graph --label compile-connected
#=> every edge here recompiles downstream files — keep this list short
mix test --cover
#=> per-module coverage %; track the trend across phases, not the absolute
Compile-time coupling is Erlang’s xref habit wearing Elixir clothes —
same disease, better tooling.
Phase 3 — Idioms & Polymorphism (Week 3)
Goal: write code that looks native (Ch 04–05).
- Convert an eager pipeline over large data to
Stream; measure memory. - Write one behaviour (with
@impl) and one protocol with twodefimpls. - Read a small library’s source starting from its
__using__macro (Ch 06).
Exit checklist:
- Can explain protocol-vs-behaviour choice in one sentence
- Comfortable reading macro-generated Phoenix/Ecto code without panic
Phase 4 — Web (Week 4)
Goal: ship a real-time feature (Ch 10).
mix phx.new realtime_demo --live; walk the generated supervision tree in Observer — recognize everything.- Build a LiveView counter/chat; add PubSub broadcast; open two tabs.
- Persist something with Ecto (schema → changeset → migration → query).
- Add an Oban worker that writes summaries of stored rows.
Exit checklist:
- Two-browser-tab real-time update working
- One DB-backed feature end-to-end (changeset validated)
- One background job retried on forced failure
Phase 5 — AI on the BEAM (Weeks 5–6)
Goal: hands-on Numerical Elixir (Part IV).
Work through the code in order, evaluating every block in your notebook:
| Order | Source | Focus |
|---|---|---|
| 1 | Ch 17 §17.3–17.7 | tensors, broadcasting, defn, autodiff |
| 2 | Ch 19 §19.1–19.3 | MNIST MLP → custom grad loop → CNN |
| 3 | Ch 20 §20.2–20.10 | HF models: text/vision/audio/embeddings |
| 4 | Bumblebee example Livebooks | end-to-end community recipes |
Round out the week with Scholar (Ch 13 §13.4) — Scholar.Cluster.KMeans.fit/2
on synthetic blobs takes five minutes and proves traditional ML shares the
same tensors and backends.
Then productionize:
- Build Ch 21’s blueprint app:
mix phx.new mnist_phoenix --live, add the four ML modules from §21.3, train, serve. - Read your four modules against Ch 21’s lessons (Model/Persistence/Serving/ServingManager).
- Modify one thing: batch size, backend, or add a probabilities endpoint.
Backend selection reminder (Ch 18): EXLA everywhere for Bumblebee; EMLX only for plain Nx on Apple Silicon; BinaryBackend for CI/debugging.
Exit checklist:
- MNIST notebook trains to >95% test accuracy locally
- Your blueprint app serves predictions from the drawn canvas
- Can articulate what
Nx.Defn.gradreturns for a map container
Phase 6 — Specialize (Weeks 7–8)
Pick ONE lane and go deep:
- Edge:
mix nerves.new blinky, burn to a Pi; wire one Circuits peripheral (Ch 16). Stretch: AtomVM on an ESP32. - Agents/RAG: extend Ch 28’s RAGPipeline with pgvector + Ollama adapter; stream answers through a LiveView.
- Data platform: Broadway pipeline from a queue into Ecto + Explorer analytics in Livebook (Operate mode attached to it).
Exit artifact: one deployed/demo-able project in your lane using ≥2 ecosystem libraries.
Milestone Exit Criteria, Measured
Each checkpoint is observable — collect the evidence, don’t self-certify:
| Week | Milestone | Measurable exit |
|---|---|---|
| 1 | Syntax | translated module compiles clean; 3 pipelines on |>; pin rule explained (Ch 25) |
| 2 | Tooling | mix test green, release boots, zero type warnings; forced child restart explained (Ch 24) |
| 3 | Idioms | Stream memory numbers recorded; behaviour + protocol merged |
| 4 | Web | two-tab update < 100 ms locally; forced job retry observed |
| 5–6 | Numerical | MNIST > 95%; serving p95 latency logged |
| 7–8 | Lane | demo URL reachable; README reproduces it from a fresh clone |
Rolling Out to a Team
- Pairing rotation: every Erlang developer pairs a week on the new Elixir service, then rotates — knowledge spreads, nobody becomes the single translator.
- Review guidelines:
mix format --check-formattedand Credo gate CI;@implmandatory on behaviour callbacks; macro-containing PRs need a written justification (see the pitfalls table below). - Style adoption order: formatter first, pipes/naming second, behaviours/protocols third, macros last — the same order as the pitfalls table. Adopting style bottom-up beats debating it.
Common Pitfalls for Erlang Developers
| Pitfall | Fix |
|---|---|
| Expecting bound vars to compare in patterns (Erlang reflex) | Elixir rebinds; use ^var to compare (Ch 25) |
Treating "str" as charlist | Strings are binaries; charlists are ~c"str" ('str' is deprecated since 1.17) |
Expecting 10 / 4 to be integer division | / always returns floats; use div/2, rem/2 (Ch 02) |
Using = where you mean exact equality | == is numeric-loose; === is the match-exact one (1 === 1.0 is false) |
| Fighting the pipe style | Data-last argument order enables |>; adopt it |
| Writing macros early | Functions + behaviours cover 95%; macros are last resort |
Skipping mix format | It’s canonical; enable in CI |
| Reaching for Redis for queues/jobs | Postgres-backed Oban usually suffices |
| Double-encoding JSON with Req | Pass maps to json:; don’t pre-call Jason.encode! (Ch 28) |
Assuming unless is fine | Soft-deprecated in 1.18 (no warning emitted) — prefer if not / explicit case; unless ... else is the confusing case |
| Using EMLX for Bumblebee notebooks | EXLA required today (Ch 18) |
| Expecting ORM-style implicitness | Ecto changesets are explicit by design |
Migration Risk Register
Project-level risks, distinct from the language pitfalls above:
| Risk | Likelihood | Mitigation |
|---|---|---|
| False confidence from easy syntax | High | pair reviews month 1; strict Credo |
| Split-brain conventions | Medium | one formatter-enforced style guide, day 1 |
| OTP mistranslation | Medium | behaviour-callback checklist in review |
| Dependency drift | Medium | pinned mix.lock; monthly mix hex.outdated |
| Perf surprises on hot paths | Low–Med | benchmark before porting |
| Onboarding ramp | Medium | this roadmap is the onboarding plan |
Tracking Migration Health
Pick three numbers; review them weekly like uptime:
| Signal | Source | Healthy trend |
|---|---|---|
| Compile-time coupling | mix xref graph --label compile-connected | shrinking |
| Test coverage | mix test --cover | rising per ported module |
| Incident attribution | alert → process via Observer/:sys/recon | falling |
Rollback Strategy Per Phase
Decide the undo before each step, not during the incident:
| Phase | Rollback move |
|---|---|
| Syntax drills | branches only — discard; nothing shipped |
| Tooling | revert mix.lock; release dirs are immutable |
| Web features | feature-flag the route; mix ecto.rollback for migrations |
| Background jobs | Oban: pause queues, drain, flip workers off |
| Prod cutover | blue-green: old node stays in the cluster one full cycle |
Rule of thumb: never migrate data you cannot unmigrate, and ship dark (wired but disabled) before cutting traffic.
Resources
Books / docs
- Machine Learning in Elixir — Sean Moriarity (PragProg)
- hexdocs: nx · axon · bumblebee · scholar · polaris · phoenix
- Nx backends guide: hexdocs.pm/nx/backends.html
Community / browsing
- ElixirForum (phoenix & nx subforums)
- Hugging Face models tagged Bumblebee: huggingface.co/models?library=bumblebee
- Livebook examples: github.com/livebook-dev/livebook/tree/main/examples
In this guide
- Ch 02 §2.6 — the Erlang↔Elixir keyword map, plus checkpoint drills per chapter
- Ch 07 §7.3 — the gradual-typing sandbox recipe (
typing_demo) - Ch 21 §21.3 — the production serving blueprint (
mnist_phoenix, assembled) - Ch 22–25 (Part V) — deep dives to keep at hand when drills get real: processes & signals, GenServer’s call protocol, supervisor strategies and restart budgets, pattern-matching execution rules
The Final Message
Erlang gave us a runtime for building reliable concurrent systems.
Elixir is building an ecosystem that takes those ideas into web, real-time, edge, mobile and AI.
You don’t need to leave Erlang behind. You already know the hardest part: BEAM + OTP. Elixir gives you more places to apply it.
The strongest career story is not “learn another language.” It is:
Become an orchestrator — build things for yourself first; opportunity and career follow.
flowchart TD
OTP["OTP
what you know"] --> EX["Elixir
types · tooling · macros · composition"]
EX --> WEB["Phoenix / LiveView ↔ Data
web · Ecto/Ash"]
WEB --> AIm["AI/ML
Nx · EXLA · EMLX · Axon · Bumblebee"]
AIm --> EDGE["IoT / Edge / Mobile
Nerves · AtomVM · Mob/Dala"]
EDGE --> EI["Edge Intelligence
local inference/training"]