Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk4 min

Elixir Enchiridium — Tomo III: OTP

A practical guide to Elixir OTP: how GenServer calls and casts differ, how supervisors restart children, and how an OTP application starts its supervision tree.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

OTP is the set of conventions and behaviours Elixir uses to organize concurrent processes and manage their lifecycles. A typical application uses GenServer for request-handling processes, supervisors to restart failed children, and an OTP application to start the top-level supervision tree. You do not need to adopt every OTP feature at once, but these pieces are central to building Elixir services that can recover in a controlled way.

What OTP means in an Elixir project

OTP is not a single library or framework layer that replaces Elixir. It is a collection of established behaviours and runtime conventions for structuring concurrent programs. In everyday Elixir work, three pieces are especially useful to understand:

  • GenServer: a common behaviour for implementing a process that handles requests and maintains state.
  • Supervisor: a process that starts, stops, and monitors child processes, and applies the restart rules declared for them.
  • OTP application: a runtime unit that can be started or stopped as a whole and that typically starts the top-level supervisor for its processes.

Mix and OTP applications are related, but they are not the same thing. Mix manages project tasks such as compiling and testing; an OTP application is the runtime unit the Erlang VM starts and stops. Elixir’s Getting Started guide to Mix and OTP explains how these concepts fit together.

How a GenServer handles requests

A GenServer process can receive requests from client code while keeping its state inside the process. The client-facing choice between a call and a cast determines what acknowledgement the caller gets.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

GenServer.call/3 waits for a reply

A call waits for the server to respond, so the caller gets a reply from the request-handling path. This makes calls appropriate when the caller needs a result or needs to know that the server handled the request before proceeding.

GenServer.cast/2 does not confirm processing

A cast returns without waiting for the server to confirm it handled the message. That asynchronous contract can be useful when the sender does not need an immediate reply. Its return alone, however, does not prove that the operation completed. A subsequent successful call can establish that the server is responding and, in the guide’s example, that earlier work has been processed. Neither choice is inherently unsafe; choose according to whether the sender needs an acknowledgement. See the official GenServer guide.

How supervisors recover from process failure

A supervisor starts child processes from their child specifications, monitors them, and applies the declared response when one terminates. The Erlang/OTP Design Principles guide describes the supervisor’s responsibility as “starting, stopping and monitoring its child processes.”

Child specifications are started in order and terminated in reverse order. Restart strategy determines how broadly a failure affects sibling processes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Strategy What happens after a child terminates When it fits
:one_for_one Only the terminated child is restarted. Use when siblings can recover independently.
:one_for_all All children are terminated and then restarted. Use when the children form a tightly coupled unit that must restart together.
:rest_for_one The terminated child and the children started after it are terminated and restarted. Use when later children depend on earlier children in start order.

These are design choices, not universal rankings. Consider which processes depend on one another and whether a coordinated restart is necessary for correctness. For example, if a later child depends on a connection or service started earlier in the same supervisor, :rest_for_one can encode that relationship: when the earlier child fails, dependent later children restart too.

Restart intensity limits repeated failure

Supervisors also have a restart-intensity limit: a maximum number of restarts within a configured time window. If that limit is exceeded, the supervisor terminates its children and itself. A higher-level supervisor can then take responsibility for recovery. This prevents a process that repeatedly fails for the same reason from restarting indefinitely.

How an OTP application starts the supervision tree

An OTP application’s callback can return a supervisor process as its top-level process. At startup, the runtime starts the application and its configured dependencies; the supervision tree then provides the structure for starting and recovering the application’s child processes. This is how GenServers and other supervised processes become part of an application rather than isolated processes started ad hoc. The Elixir supervisor and application guide walks through this arrangement.

The relationship is useful to keep straight: Mix helps you work on the project, while the OTP application defines a runtime unit. Starting the application starts its dependencies and application callback; stopping it treats that runtime unit as a whole.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Do you need OTP for an Elixir app?

If an Elixir program has processes that need supervision, managed state, or coordinated startup and shutdown, OTP provides the standard building blocks for those responsibilities. A small script may not need a complex supervision tree, but learning GenServer and supervisors becomes valuable when an application’s processes must keep running, recover from crashes, or depend on one another.

You can learn the ideas incrementally: first understand processes and GenServer request semantics, then supervise related processes, and finally connect the tree to the application callback. When choosing a strategy, base it on actual process dependencies rather than selecting the most comprehensive-sounding option.

Elixir and Erlang/OTP compatibility

At the time of the official documentation snapshot used here, the Elixir documentation labeled Elixir v1.20.4 stable and listed Erlang/OTP versions 27, 28, and 29 as supported. Compatibility changes with releases, so check the official Elixir documentation for the Elixir version you install. Its versioned documentation is also useful when a project is on an older release; do not assume every current API or instruction applies unchanged to it.

Where to continue learning

The official Elixir Learning page collects books, courses, videos, and other resources. For a book-length treatment, the publisher’s contents for Elixir in Action, Third Edition include generic server processes and GenServer, fault tolerance and supervisors, supervision trees and dynamic supervision, OTP applications, releases, and distributed systems.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.