Elixir's OTP framework provides battle-tested abstractions for fault-tolerant concurrent systems. These exercises test your understanding of GenServer, supervision strategies, ETS for concurrent state, process registration, and dynamic process management.
0 / 5 completed
1 / 5
At standup, a colleague asks what a GenServer is in Elixir OTP. What is the correct answer?
GenServer is the foundational OTP behaviour for building stateful server processes. You implement callbacks: handle_call/3 for synchronous request-reply, handle_cast/2 for fire-and-forget messages, and handle_info/2 for arbitrary Erlang messages. State is passed through each callback and returned as the new state, kept in a single-process loop. GenServers are the building block for caches, connection pools, and domain state machines in Elixir applications.
2 / 5
During a PR review, a teammate asks what Supervisor strategies control. Which answer is correct?
OTP Supervisor strategies define crash recovery behaviour. :one_for_one — the most common — restarts only the failed child process. :one_for_all restarts all children when any one fails, useful when children are tightly coupled. :rest_for_one restarts the failed child and all children that were started after it, useful for ordered dependency chains. Combined with max_restarts and max_seconds, strategies prevent infinite restart loops.
3 / 5
In a design review, the team discusses using ETS (Erlang Term Storage) in Elixir. A junior engineer asks what makes it different from a GenServer for caching. What is correct?
ETS (Erlang Term Storage) is a concurrent in-memory store built into the BEAM. Unlike a GenServer — where all reads and writes serialise through a single process — ETS allows multiple processes to read and write concurrently (with the appropriate access mode). This makes ETS far better than a GenServer for read-heavy caches, lookup tables, or counters where the bottleneck of single-process message passing is unacceptable.
4 / 5
An incident report shows child processes failing to register because their names conflict. A senior engineer asks what Registry provides in Elixir. What is correct?
Elixir's Registry is a local, decentralised process registry. Processes register themselves under a key (Registry.register/3), and other processes look them up (Registry.lookup/2) to get the PID without knowing it statically. It supports :unique keys (one process per key) and :duplicate keys (pub/sub pattern). It is far more scalable than a single GenServer name registry and avoids atom-based naming for dynamic process collections.
5 / 5
During a code review, a senior engineer asks when to use DynamicSupervisor instead of a regular Supervisor. What is accurate?
DynamicSupervisor is designed for situations where the number and identity of child processes are not known at startup. You start it empty and add children at runtime with DynamicSupervisor.start_child/2 — for example, spawning a GenServer per WebSocket connection or per background job. A regular Supervisor expects its child specs to be defined upfront in init/1, making it unsuitable for dynamic workloads.