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 29 — Architecture Philosophy: BEAM Orchestrates

The value of the Elixir ecosystem is not any single library. It is the architecture created by composing them — a pattern an Erlang developer already knows by heart.

29.1 The Three-Layer Picture

flowchart TD
    EX["Elixir"] --> WEB["Web<br/>Phoenix"]
    EX --> RT["Realtime<br/>OTP"]
    EX --> AI["AI<br/>Nx"]
    WEB --> BEAM["BEAM"]
    RT --> BEAM
    AI --> BEAM
    BEAM --> NB["Native Backends"]
    NB --> HW["CPU / GPU / Device"]

The philosophy in one line:

BEAM handles orchestration. Specialized runtimes handle specialized computation.

It applies across every domain:

DomainElixir describesNative runtime executes
WebPhoenix, controllers, LiveViewthe browser + BEAM schedulers
DataEcto / Explorer queriesDatabase engines
AINx / Axon graphsXLA / MLX / llama.cpp
IoTNerves / AtomVM supervisionLinux kernel / MCU hardware
MobileMob / Dala logicSwiftUI / Jetpack Compose
NativeRustler/NIF interfacesRust / C

The Chain, Concretely

The five-layer chain below resolves to named building blocks. Read the table bottom-up: incidents start at the bottom, and the architecture question is always “what does the layer above do when this one dies?”

Chain layerConcrete techWhen it fails
Specialized runtimePostgres, XLA, llama.cppblack box; degrade gracefully
External capabilityReq/Finch, Port, Rustler NIFerror tuple/timeout to caller
MessagePubSub, GenStage, Broadwayredelivered/dropped per contract
ProcessGenServer, LiveView, Nx.Servingcrash contained; restarted
SupervisorSupervisor, restart intensitylast resort — escalates upward

29.2 You Already Know This Pattern

This is exactly how gen_server calls into a Port or NIF — generalized. Read bottom-up (a request flows downward; a failure propagates upward):

flowchart TD
    NAT["Native / specialized runtime"] --> EXT["External capability<br/>Port · NIF · HTTP · gRPC"]
    EXT --> MSG["Messages<br/>async · sync · PubSub"]
    MSG --> PROC["Processes<br/>GenServer · GenStage · LiveView"]
    PROC --> SUP["Supervisor"]

The BEAM doesn’t need to become the GPU runtime, database engine, or device firmware. It is the reliable coordinator. That’s why the same runtime now spans cloud → edge → devices → accelerators.

29.3 From Infrastructure to Product

Erlang historically owned infrastructure-heavy systems. The ecosystem lets the same foundation move closer to the product:

Distributed systems → messaging + concurrency → real-time backend
→ web application → data pipeline → edge device → AI-powered application
DomainExamplesBEAM Advantage
SaaSmulti-tenant platformsisolation, supervision
Fintechtrading, ledgersfault tolerance, auditability
Real-time collabdocs, whiteboardsstateful connections, Presence
Messagingchat, notificationsgen_server, clustering
Live trackingsports, bettinglow latency, massive concurrency
Data platformsETL, analyticsBroadway/GenStage backpressure
IoTgateways, roboticsNerves, AtomVM, watchdogs
Edge inferencesmart cameraslocal Nx, privacy, offline
AI-enabled appsRAG, agents, copilotsorchestration + native inference

29.4 Why Now?

  • Phoenix/LiveView made BEAM ideas product-facing for the web.
  • Nx/Axon/Bumblebee opened ML without leaving the runtime.
  • Nerves/AtomVM pushed it onto devices.
  • Gradual typing (Ch 07) is landing without breaking the ecosystem.

The Deployment Story, Honestly

mix release emits a directory: ERTS bundled, runtime.exs for environment-driven config, and two commands that matter here — bin/<app> rpc 'EXPR' evaluates one expression on the running node, while bin/<app> remote drops you into an interactive remote shell. (bin/<app> rpc alone is not “a shell”; that distinction costs an afternoon once.) You trade a single-file artifact for live introspection — attach to production, inspect any process, run a migration check without redeploying. Containers level most of the difference; pick per ops culture, not ideology.

The valuable career skill is not “I know Elixir.” It is:

“I can build reliable distributed systems and apply the BEAM across modern application domains.”

Architecture · distributed systems · real-time · edge · AI integration — high-leverage systems engineering.

Four Things This Chapter Owes You

The five-layer chain above is a claim about code. These are the claims about deployment an Erlang team inherits and Elixir does not change:

Distribution. Nothing new, but nothing automatic either. Nodes cluster via :pg (a built-in) for process discovery, Phoenix.PubSub for message broadcast, and :rpc/:erpc for calls across the cluster. libcluster handles the gossip and the DNS-based discovery most fleets actually use:

topologies = [
  dns: [
    strategy: Cluster.Strategy.DNSPoll,
    config: [query: "my-app.example.com", node_basename: "my-app",
             polling_interval: 5_000]
  ]
]

children = [
  {Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]},
  {Phoenix.PubSub, name: MyApp.PubSub}
]

The hosting question. Fly.io, Render, Railway, or a plain VPS with a systemd unit calling bin/<app> daemon. Ch 09 has the release mechanics; this is the operational wrapper.

Observability. Telemetry events (Ch 10 §10.7, Ch 27 §27.5) → Telemetry.Metrics → LiveDashboard or Prometheus. This is the layer that makes “what does the layer above do when this one dies” answerable in production instead of in your head.

Rollback. Immutable images plus a database migration that can go backwards — or, when it cannot, an expand/contract migration sequence. Ch 30’s rollback-per-phase table is the same discipline at migration scale.

None of this is Elixir-specific; that is the point. The runtime is the same one you already know, which means the operational playbook transfers too.

Explore More

  • The Beam Book — distribution, scheduling, and memory internals behind every claim in §29.1–29.3
  • Designing for Scalability with Erlang/OTP (Hésson & Vinoski) — the architecture patterns Elixir inherits wholesale
  • Phoenix deployment guides — where the “BEAM orchestrates” pattern meets real infrastructure
  • Exercise idea: draw your current system as §29.1’s five-layer chain — mark each layer’s failure blast radius, and note which boundaries already let it crash safely

Checkpoint

  1. What role does the BEAM play when XLA does the math?
  2. Name the five layers of the orchestration chain and what each contributes.
  3. What is the pattern shared between a GenServer calling a Port and an app calling an LLM?
Answers
  1. Reliable coordinator: sessions, streaming, queues, supervision, distribution around the accelerator.
  2. Specialized runtime → external capability → message → process → supervisor; each boundary defines a failure contract.
  3. Supervisor → process → message → external capability → specialized runtime. Identical shape at every scale.

Next: Chapter 30 — The Migration Roadmap