Build a stateful service with Erlang/OTP
8 steps · about 4 h 40 min · Intermediate
- Model requests and state with Erlang terms (reference, Erlang documentation, 30 min)
Tuples, maps, lists and atoms provide a compact vocabulary for messages and service state.
- Validate messages with patterns and guards (reference, Erlang documentation, 40 min)
Function clauses and guards reject malformed requests before they reach state changes.
- Expose a small module interface (reference, Erlang documentation, 25 min)
An explicit export list separates the client API from callback implementation details.
- Document request and reply contracts (reference, Erlang documentation, 30 min)
Type specifications make expected message shapes visible to readers and static analysis.
- Understand process links and messages (reference, Erlang documentation, 35 min)
Process identity, mailboxes and exit signals explain how the service communicates and fails.
- Implement state with the gen_server behaviour (guide, Erlang documentation, 50 min)
Standard callbacks define synchronous calls, asynchronous casts and state transitions consistently.
- Report and classify service failures (reference, Erlang documentation, 30 min)
Error classes and stack traces distinguish invalid requests from unexpected process defects.
- Test calls, casts and invalid requests with EUnit (guide, Erlang EUnit documentation, 40 min)
Focused tests make the server's reply and state-transition contract repeatable.