liveBook · Manning

Worker

As explained in Elixir in Action, Third Edition

A worker process is a supervised process that performs part of a service's operational work rather than organizing other processes.

A worker process performs a system service, while a supervisor manages process life cycles. Workers provide the actual services of a concurrent system; supervisors detect failures and restart them. section 8.3

Workers can also execute independent operations outside a central server process. One-off workers keep request handling short and allow new requests to proceed concurrently, although unrestricted spawning can overload I/O resources. section 7.3.4

In a supervision tree, workers provide the operational boundaries that make failure and service management tractable:

  • Run each worker under a supervisor so a crashed service can be restarted independently. section 9.0
  • Group related workers into services such as a database or cache, then organize those services beneath supervisors. section 9.1.6
  • Use one-off workers for independent reads or writes when the central process must remain responsive. section 7.3.4

Concurrent database operation

A database server can spawn a worker for a file write and immediately return. For a synchronous read, the worker performs the operation and calls GenServer.reply/2 while the server returns {:noreply, state}. section 7.3.4

Figure 9.4 Supervision tree
CH09_F04_Juric3

A supervision-tree diagram shows workers as service components beneath supervisors, making restart boundaries and failure propagation visible. section 9.1.6

How Elixir in Action, Third Edition covers it

How deep it goes
Defines workers, demonstrates spawned request handlers, and places them in supervision trees; it stops short of exhaustive process internals.
Examples
Uses Todo.DatabaseWorker, to-do cache and server processes, and spawned file-read and file-write handlers.
What it assumes
Assumes concurrent processes and request handling, while teaching the distinction between service workers and supervising processes.
What you can do after
Operate/configure concurrent services by separating work into workers and placing restart boundaries under supervisors.
How it connects
Connects workers with supervisors, supervision trees, processes, GenServer, fault tolerance, and error isolation.

Also explained in

Compare how 9 books explain worker →

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.