Stateful Processes
- GenServer. A GenServer is the stateful-process behaviour: OTP’s battle-tested loop with your callbacks.
- init and state. init builds the initial state: threaded through every callback thereafter.
- Process dictionary honestly. State lives in the callback returns: not the process dictionary, which hides data from everyone.
Calls and Casts
- handle_call. call is synchronous: the caller waits for a reply, with a timeout guarding it.
- handle_cast. cast is fire-and-forget: no reply, no confirmation, chosen deliberately.
- handle_info. handle_info receives everything else: monitors’ :DOWN, timers, raw messages.
Designing Reliable Servers
- Small state, clear API. A good server owns one concern: its public API functions wrapping the message protocol.
- Timeouts and hibernate. Servers declare call timeouts and hibernate when idle: long-lived processes tuned by contract.
- Avoid blocking the loop. Slow work leaves the server: tasks do the waiting, the loop stays responsive.
Before and after this level
- Before: Level 6: Tasks & Agents: Tasks, Agents, Managing Concurrent Work.
- Next: Level 8: Supervision & OTP: Supervisors, Supervision Trees, Fault-Tolerant Applications.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Elixir Level 7: GenServer cover?
Stateful Processes, Calls and Casts, Designing Reliable Servers: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 6: Tasks & Agents, which covers Tasks, Agents, Managing Concurrent Work.