Elixir OTP Concurrency & GenServer
When to use
Use this skill when you need to building resilient, fault-tolerant concurrent services using Elixir GenServer, Supervisors, and message passing.
Prerequisites
- Working knowledge of relevant programming language or database fundamentals.
- Access to testing environment or local runtime instance.
Step-by-step workflow
- Analyze operational requirements: Review performance boundaries, data integrity constraints, and query patterns.
- Design schema / interface: Define explicit data contracts, types, or indexes supporting planned operations.
- Implement core routines: Construct declarative, type-safe, or parameterized queries and functions.
- Validate performance: Verify execution metrics using profilers, EXPLAIN plans, or benchmark test suites.
- Implement defensive controls: Enforce timeout boundaries, connection pooling limits, and transaction safety.
Commands / code examples
defmodule RateLimiter do
use GenServer
# Client API
def start_link(initial_limit) do
GenServer.start_link(__MODULE__, initial_limit, name: __MODULE__)
end
def allow_request?() do
GenServer.call(__MODULE__, :check_request)
end
# Server Callbacks
@impl true
def init(limit) do
{:ok, %{limit: limit, current: 0}}
end
@impl true
def handle_call(:check_request, _from, %{limit: limit, current: cur} = state) do
if cur < limit do
{:reply, true, %{state | current: cur + 1}}
else
{:reply, false, state}
end
end
end
Common mistakes & pitfalls
- Overlooking indexing strategies on foreign keys and frequently queried filter columns.
- Running unparameterized dynamic queries, creating severe SQL injection vulnerabilities.
- Holding open long-running database transactions during slow external network calls.
Verification checklist
Related skills
- postgresql-query-optimization-explain
- sql-anti-patterns-remediation
- acid-transactions-isolation-levels
- secure-code-review-static-analysis-sast
1---2name: elixir-otp-concurrency3description: Use this skill when building resilient, fault-tolerant concurrent services using Elixir GenServer, Supervisors, and message passing.4metadata:5 source: https://skillmd.com/skills/nextboxis/elixir-otp-concurrency6---78# Elixir OTP Concurrency & GenServer910## When to use11Use this skill when you need to building resilient, fault-tolerant concurrent services using Elixir GenServer, Supervisors, and message passing.1213## Prerequisites14- Working knowledge of relevant programming language or database fundamentals.15- Access to testing environment or local runtime instance.1617## Step-by-step workflow181. **Analyze operational requirements**: Review performance boundaries, data integrity constraints, and query patterns.192. **Design schema / interface**: Define explicit data contracts, types, or indexes supporting planned operations.203. **Implement core routines**: Construct declarative, type-safe, or parameterized queries and functions.214. **Validate performance**: Verify execution metrics using profilers, EXPLAIN plans, or benchmark test suites.225. **Implement defensive controls**: Enforce timeout boundaries, connection pooling limits, and transaction safety.2324## Commands / code examples25```elixir26defmodule RateLimiter do27 use GenServer2829 # Client API30 def start_link(initial_limit) do31 GenServer.start_link(__MODULE__, initial_limit, name: __MODULE__)32 end3334 def allow_request?() do35 GenServer.call(__MODULE__, :check_request)36 end3738 # Server Callbacks39 @impl true40 def init(limit) do41 {:ok, %{limit: limit, current: 0}}42 end4344 @impl true45 def handle_call(:check_request, _from, %{limit: limit, current: cur} = state) do46 if cur < limit do47 {:reply, true, %{state | current: cur + 1}}48 else49 {:reply, false, state}50 end51 end52end53```5455## Common mistakes & pitfalls56- Overlooking indexing strategies on foreign keys and frequently queried filter columns.57- Running unparameterized dynamic queries, creating severe SQL injection vulnerabilities.58- Holding open long-running database transactions during slow external network calls.5960## Verification checklist61- [ ] Schema contracts and type signatures are strictly enforced.62- [ ] Queries are fully parameterized against injection vulnerabilities.63- [ ] Profiling or execution plans show optimal resource consumption.64- [ ] Error handling safely releases locks and rolls back aborted transactions.6566## Related skills67- postgresql-query-optimization-explain68- sql-anti-patterns-remediation69- acid-transactions-isolation-levels70- secure-code-review-static-analysis-sast