elixir-stack
Installation
SKILL.md
Elixir stack
Regent sites are Phoenix and Ash on Postgres. Before you design, build or review Elixir code, name the standard tool for every moving part. A smaller copy of a standard tool is a defect, however correct the copy is.
The standard tool for each job
| Job | Use | Never |
|---|---|---|
| Work that must survive a restart, retry, run later, run on a schedule or call another service | Oban; in an Ash resource, AshOban | GenServer loops, Process.send_after polling, Task.start, status, attempt or lease columns |
| Record that something happened, in order | A table written in the same transaction as the change (an event log or outbox) | Ash notifiers or PubSub alone: they run after commit and can be lost |
| Tell open pages or other processes that something changed | Phoenix.PubSub, paired with Oban or a table when it must not be lost |
Polling the database |
| Data, constraints and locks | Ash actions on AshPostgres; Ecto for migrations and justified queries | Uniqueness checked in code without a database constraint |
| Call another website | Req | HTTPoison, :httpc; Mint only where Req cannot do it, such as connecting to an address checked in advance |
| Short concurrent work inside one request | Task.async_stream, Task.Supervisor |
Unsupervised spawn |
| In-memory state one process owns | A supervised GenServer or Agent, named through Registry |
A GenServer as a job queue or as a copy of database rows |
| Fast read-mostly lookups | ETS or :persistent_term |
A GenServer.call bottleneck |
| Measurements | :telemetry events |
Ad hoc log lines |