usage-rules-otp
OTP Usage Rules
When & Why to Use This Skill
This Claude skill provides a comprehensive set of best practices and architectural guidelines for Elixir/Erlang OTP (Open Telecom Platform). It serves as a specialized knowledge base for building resilient, concurrent, and fault-tolerant systems, focusing on GenServer optimization, process communication strategies, and robust supervision trees.
Use Cases
- Architecting scalable backend systems: Use these rules to design Elixir applications that handle high concurrency with proper back-pressure and timeout management.
- Code Review and Quality Assurance: Apply these standards during peer reviews to ensure GenServers maintain simple state and implement proper cleanup in the terminate/2 callback.
- Fault Tolerance Configuration: Guide the setup of Supervisors with optimal restart strategies (max_restarts, max_seconds) to prevent cascading failures and infinite loops.
- Async Task Management: Implement Task.Supervisor and async_stream patterns to handle background processing while maintaining system stability and resource control.
| name | usage-rules-otp |
|---|---|
| description | OTP Usage Rules |
OTP Usage Rules
GenServer Best Practices
- Keep state simple and serializable
- Handle all expected messages explicitly
- Use
handle_continue/2for post-init work - Implement proper cleanup in
terminate/2when necessary
Process Communication
- Use
GenServer.call/3for synchronous requests expecting replies - Use
GenServer.cast/2for fire-and-forget messages. - When in doubt, use
callovercast, to ensure back-pressure - Set appropriate timeouts for
call/3operations
Fault Tolerance
- Set up processes such that they can handle crashing and being restarted by supervisors
- Use
:max_restartsand:max_secondsto prevent restart loops
Task and Async
- Use
Task.Supervisorfor better fault tolerance - Handle task failures with
Task.yield/2orTask.shutdown/2 - Set appropriate task timeouts
- Use
Task.async_stream/3for concurrent enumeration with back-pressure