usage-rules-otp

OTP Usage Rules

⭐2stars🔀0forks📁View on GitHub🕐Updated Oct 21, 2025

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.
nameusage-rules-otp
descriptionOTP Usage Rules

OTP Usage Rules

GenServer Best Practices

  • Keep state simple and serializable
  • Handle all expected messages explicitly
  • Use handle_continue/2 for post-init work
  • Implement proper cleanup in terminate/2 when necessary

Process Communication

  • Use GenServer.call/3 for synchronous requests expecting replies
  • Use GenServer.cast/2 for fire-and-forget messages.
  • When in doubt, use call over cast, to ensure back-pressure
  • Set appropriate timeouts for call/3 operations

Fault Tolerance

  • Set up processes such that they can handle crashing and being restarted by supervisors
  • Use :max_restarts and :max_seconds to prevent restart loops

Task and Async

  • Use Task.Supervisor for better fault tolerance
  • Handle task failures with Task.yield/2 or Task.shutdown/2
  • Set appropriate task timeouts
  • Use Task.async_stream/3 for concurrent enumeration with back-pressure