liveBook · Manning

Concurrency

As explained in Elixir in Action, Third Edition

Concurrency is the capability for multiple computational activities to make progress during overlapping periods of execution.

Concurrency lets multiple computational activities make progress during overlapping execution. In server-side systems, it keeps request handling, shared state, and background jobs responsive as demand grows. section 1.1 section 5.1

BEAM implements concurrency with lightweight processes rather than heavyweight operating-system threads or processes. Processes share no memory, communicate through asynchronous messages, and are scheduled across available CPU cores. section 1.1.2 section 5.1

This design gives concurrent systems several practical properties:

  • Isolate failures: a process crash normally leaves unrelated processes running and avoids corrupting their memory. section 8.2
  • Scale execution: many processes can use available CPU cores without one lengthy task blocking every pending request. section 5.1
  • Simplify synchronization: asynchronous messages replace shared-memory locks, mutexes, and semaphores. section 1.1.2
  • Support distribution: process communication works similarly within one BEAM instance or across remote instances. section 1.1.2

Starting work concurrently

In Elixir, spawn(fn -> ... end) creates a BEAM process and returns its PID immediately. The caller can continue while the new process runs. A closure can carry a query definition into the new process; because processes share no memory, the data is copied. Running five two-second queries concurrently returns immediately and prints their results together rather than waiting roughly ten seconds sequentially. section 5.2.1

Production designs assign independent work to separate processes. An HTTP server can give each connection or request its own process, allowing simultaneous requests to proceed independently while requests targeting the same stateful process are handled one by one. section 11.3.4

Figure 1.1 Concurrency in the Erlang virtual machine
CH01_F01_Juric3

Use the BEAM scheduling diagram to relate one operating-system process and a few scheduler threads to many concurrent BEAM processes. section 1.1.2

How Elixir in Action, Third Edition covers it

How deep it goes
Explains BEAM processes, scheduling, message passing, isolation, spawning, and request architecture, while deferring detailed recovery mechanisms.
Examples
Uses concurrent query execution, isolated to-do servers, and per-request HTTP processes to demonstrate implementation and production behavior.
What it assumes
Assumes server-side workload concerns while teaching the BEAM process model, process isolation, and asynchronous communication directly.
What you can do after
Build it from scratch by spawning lightweight processes, passing data through closures, and assigning independent requests to separate processes.
How it connects
Connects process isolation and message passing with fault tolerance, scalability, distribution, and server-side systems.

Also explained in

Compare how 23 books explain concurrency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.