Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

  1. 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.
  2. Install Livebook: brew install livebook (or mix escript.install hex livebook).
  3. 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.

  1. Work through Ch 02 tables; translate one of your own .erl modules by hand.
  2. Drill the differences: strings-are-binaries, fn vs fun, @attr vs -define, structs vs records.
  3. Practice pipes until nested calls feel wrong: rewrite three list pipelines with |> + Enum.
  4. 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).

  1. mix new drill --sup; add a GenServer child — after skimming Ch 23, so the catch-all handle_info, call timeouts, and terminate truth table are right from day one; write ExUnit tests.
  2. Add a Hex dep, call an Erlang module (:lists, :ets) from Elixir code.
  3. Run mix format, mix docs (add ex_doc), build mix release (Ch 09).
  4. Turn on the type checker: read every warning from mix compile (Ch 07 §7.3’s typing_demo scratch project is the sandbox).
  5. Kill your own GenServer mid-request and watch the supervisor rebuild it (Ch 22–24) — restart budgets, :rest_for_one ordering, 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).

  1. Convert an eager pipeline over large data to Stream; measure memory.
  2. Write one behaviour (with @impl) and one protocol with two defimpls.
  3. 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).

  1. mix phx.new realtime_demo --live; walk the generated supervision tree in Observer — recognize everything.
  2. Build a LiveView counter/chat; add PubSub broadcast; open two tabs.
  3. Persist something with Ecto (schema → changeset → migration → query).
  4. 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:

OrderSourceFocus
1Ch 17 §17.3–17.7tensors, broadcasting, defn, autodiff
2Ch 19 §19.1–19.3MNIST MLP → custom grad loop → CNN
3Ch 20 §20.2–20.10HF models: text/vision/audio/embeddings
4Bumblebee example Livebooksend-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:

  1. Build Ch 21’s blueprint app: mix phx.new mnist_phoenix --live, add the four ML modules from §21.3, train, serve.
  2. Read your four modules against Ch 21’s lessons (Model/Persistence/Serving/ServingManager).
  3. 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.grad returns 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:

WeekMilestoneMeasurable exit
1Syntaxtranslated module compiles clean; 3 pipelines on |>; pin rule explained (Ch 25)
2Toolingmix test green, release boots, zero type warnings; forced child restart explained (Ch 24)
3IdiomsStream memory numbers recorded; behaviour + protocol merged
4Webtwo-tab update < 100 ms locally; forced job retry observed
5–6NumericalMNIST > 95%; serving p95 latency logged
7–8Lanedemo 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-formatted and Credo gate CI; @impl mandatory 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

PitfallFix
Expecting bound vars to compare in patterns (Erlang reflex)Elixir rebinds; use ^var to compare (Ch 25)
Treating "str" as charlistStrings 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 styleData-last argument order enables |>; adopt it
Writing macros earlyFunctions + behaviours cover 95%; macros are last resort
Skipping mix formatIt’s canonical; enable in CI
Reaching for Redis for queues/jobsPostgres-backed Oban usually suffices
Double-encoding JSON with ReqPass maps to json:; don’t pre-call Jason.encode! (Ch 28)
Assuming unless is fineSoft-deprecated in 1.18 (no warning emitted) — prefer if not / explicit case; unless ... else is the confusing case
Using EMLX for Bumblebee notebooksEXLA required today (Ch 18)
Expecting ORM-style implicitnessEcto changesets are explicit by design

Migration Risk Register

Project-level risks, distinct from the language pitfalls above:

RiskLikelihoodMitigation
False confidence from easy syntaxHighpair reviews month 1; strict Credo
Split-brain conventionsMediumone formatter-enforced style guide, day 1
OTP mistranslationMediumbehaviour-callback checklist in review
Dependency driftMediumpinned mix.lock; monthly mix hex.outdated
Perf surprises on hot pathsLow–Medbenchmark before porting
Onboarding rampMediumthis roadmap is the onboarding plan

Tracking Migration Health

Pick three numbers; review them weekly like uptime:

SignalSourceHealthy trend
Compile-time couplingmix xref graph --label compile-connectedshrinking
Test coveragemix test --coverrising per ported module
Incident attributionalert → process via Observer/:sys/reconfalling

Rollback Strategy Per Phase

Decide the undo before each step, not during the incident:

PhaseRollback move
Syntax drillsbranches only — discard; nothing shipped
Toolingrevert mix.lock; release dirs are immutable
Web featuresfeature-flag the route; mix ecto.rollback for migrations
Background jobsOban: pause queues, drain, flip workers off
Prod cutoverblue-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

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"]

Back to table of contents