Pilotwave
Enqueue email in Django, deliver it from a tiny Rust daemon. Postgres is the only queue. No Redis, no RabbitMQ, no second Django in RAM.
Pilotwave is a two-part email outbox for Django:
- Producer (Python): your view calls
mail_notification.enqueue(...)— a single PostgresINSERTviadjango.tasks+django-tasks-db. The request returns immediately, no SMTP in the request cycle. - Worker (Rust): the static
pilotwave-workerbinary polls Postgres withFOR UPDATE SKIP LOCKED, sends via SMTP, marks the rowSUCCESSFUL/FAILED, and upserts a heartbeat row.
Django renders, Pilotwave delivers.
Why this exists
Small VPS / shared hosting where you can afford Django + Postgres + Nginx and little else:
- A resident Python worker (
db_worker, Celery worker) costs a full Django RSS just to poll — typically 80–180 MB. - Redis also needs its own daemon and memory (we saw ~100 MB growth trigger the OOM-killer on a shared host), plus backup/monitoring.
- Pilotwave replaces both with one ~5 MB static binary that speaks Postgres and SMTP directly.
Measured on this repo (just benchmark, 100 identical mails, fake SMTP, VmRSS from /proc):
| worker | RSS max | RSS idle mean | PSS max |
|---|---|---|---|
| minimal Python poller (stdlib + psycopg, no Django) | 49,428 kB | 49,428 kB | 41,007 kB |
pilotwave-worker release |
5,028 kB | 5,028 kB | 3,012 kB |
| ratio | 9.8x less | 9.8x less | 13.6x less |
Details, scripts and caveats: benchmark/. The Python baseline is deliberately best-case (no validation, no Django); a real db_worker uses more.
Non-goals: worker speed/throughput, sub-second latency, general task queue. Poll interval defaults to 1.5–5 s. If you need high-volume or precise scheduling, use Celery.
Features
- No broker to operate. If you have Postgres, you already have the queue.
- Small idle footprint. Single-threaded Tokio, 1 Postgres connection,
opt-level=z + lto + strip. - Crash-safe claim. Atomic
UPDATE … FOR UPDATE SKIP LOCKED, ordered bypriority DESC, run_after, enqueued_at. Multiple workers can coexist. - Fail-closed safety. Attachment roots required (
PILOTWAVE_ATTACHMENT_ROOTS, noMEDIA_ROOTfallback), header/injection checks, secret redaction, least-privilege DB roles. - Observable.
pilotwave_heartbeatrow (last_seen, counters,last_error_code), plusstatus/list/inspectCLI (read-only DSN supported). - Contract-tested. Python and Rust share contracts/CONTRACT.md; drift fails the test suite.
Limitations (read before adopting)
Status: v0.1.0 alpha. Email-only, API unstable, production hardening in progress.
- At-least-once delivery. Crash after send + zombie-reaper can duplicate a mail. Producers must be idempotent by
reference(same reference = same content). No dedupe table in v1. - Email-only, Postgres-only. No Python fallback ships in v1 — only
pilotwave-workerdrains thepilotwave.emailqueue. - Polling, not push. Expect seconds of delay, 2 MiB row limit, 10 MiB attachments total, 6 MiB per file.
- One machine, one benchmark. Numbers above are from a single host/run — re-run
just benchmarkbefore quoting.
How it works
flowchart LR
View[Django view] -->|mail_notification.enqueue: INSERT| PG[(Postgres: django_tasks_database_dbtaskresult)]
PG -->|claim FOR UPDATE SKIP LOCKED| RW[pilotwave-worker Rust]
RW -->|SMTP| SMTP[(mail server)]
RW -->|SUCCESSFUL/FAILED| PG
RW -->|upsert last_seen + counters| HB[(pilotwave_heartbeat)]
Requirements
- Python 3.14, Django 6.x
- Postgres 15+ (dev compose uses
postgres:18) - SMTP server (any; dev uses Mailcrab on
:1025, UI on:1080)
Install
uv add pilotwave
# provides both the Django app and the pilotwave-worker binary in .venv/bin/
Or from source:
cp .env.example .env
just sync # uv + cargo deps
just dev-up # local Postgres + Mailcrab (dev only)
just migrate # Django migrations
Quickstart (5 minutes)
1. Settings (settings.py):
INSTALLED_APPS = [
"django_tasks_db",
"pilotwave",
# …
]
TASKS = {
"default": {"BACKEND": "django_tasks_db.DatabaseBackend", "QUEUES": ["default", "pilotwave.email"]}
}
2. Enqueue from your view (PRG so refresh never double-enqueues):
from django.db import transaction
from pilotwave.tasks import mail_notification
reference = f"order-{order.id}"
# `enqueue` INSERTs immediately (no on_commit deferral): inside a
# transaction, defer it explicitly so a rollback never publishes the row.
transaction.on_commit(
lambda: mail_notification.enqueue(
to="user@example.com",
subject="Your order shipped",
reference=reference,
text_body="Hi, your order is on its way.",
)
)
The task is pilotwave.tasks.mail_notification (@task(queue_name="pilotwave.email")) — shipped by the package, no tasks.py to write in your app. Its body never runs in production (Rust reads the Postgres row directly); it only runs in tests / eager mode.
See example/demo/ for a runnable app.
What gets stored:
args_kwargs = {"args": [], "kwargs": {reference, to, subject, text_body/html_body, …}}. Full rules: contracts/CONTRACT.md.
3. Run the worker (needs PILOTWAVE_DATABASE_URL + EMAIL_* from .env):
pilotwave-worker run --fg # foreground loop (systemd/Docker)
pilotwave-worker run # oneshot: claim one READY task, then exit
pilotwave-worker status # queue counts + daemon + heartbeat
Minimal .env:
PILOTWAVE_DATABASE_URL=postgres://pilotwave_worker:CHANGEME@localhost:5432/pilotwave
PILOTWAVE_ATTACHMENT_ROOTS=/srv/app/media
EMAIL_HOST=smtp.example.com
EMAIL_PORT=587
EMAIL_USE_TLS=true
EMAIL_HOST_USER=you@example.com
EMAIL_HOST_PASSWORD=secret
DEFAULT_FROM_EMAIL="App <noreply@example.com>"
Full reference: .env.example.
Configuration
| Key | Purpose | Default |
|---|---|---|
PILOTWAVE_DATABASE_URL |
Worker DSN (least-privilege role, never DATABASE_URL) |
required |
PILOTWAVE_DATABASE_URL_RO |
Read-only DSN for status/list/inspect |
falls back to worker DSN |
PILOTWAVE_TASK_PATHS |
Task allowlist (defaults to shipped task) | pilotwave.tasks.mail_notification |
PILOTWAVE_QUEUE_NAME / PILOTWAVE_BACKEND_NAME |
Claim scope | pilotwave.email / default |
PILOTWAVE_POLL_MIN_MS / MAX_MS |
Backoff when queue empty | 1500 / 5000 |
PILOTWAVE_MAX_ATTEMPTS |
Transient SMTP retries before smtp_exhausted |
5 |
PILOTWAVE_ATTACHMENT_ROOTS |
Absolute prefixes; empty = deny all | fail-closed, no fallback |
EMAIL_HOST/PORT/USE_TLS/HOST_USER/HOST_PASSWORD |
SMTP used by Rust worker | required |
PILOTWAVE_ALLOW_PLAINTEXT_SMTP |
Allow USE_TLS=false (dev only, fail-loud in prod) |
false |
PILOTWAVE_PID_FILE / LOG_FILE |
--bg daemon files |
unset (foreground) |
Production roles (see .env.example):
GRANT SELECT, UPDATE ON django_tasks_database_dbtaskresult TO pilotwave_worker;
GRANT INSERT, UPDATE ON pilotwave_heartbeat TO pilotwave_worker;
Outside localhost, non-TLS DSNs and plaintext SMTP fail loud — set ?sslmode=require.
Production notes
- Run
pilotwave-worker run --fgunder systemd/Docker withRestart=always.--bgdaemon mode exists but foreground + supervisor is preferred. - Scale horizontally with more workers —
SKIP LOCKEDprevents double-claim. Expect duplicates only on crash-after-send (at-least-once). - Monitor
pilotwave_heartbeat(key='pilotwave_worker'): alert iflast_seenis stale ormetadata.last_error_codeissmtp_transient/smtp_exhausted. - Attachments: declare
attachment_paths+attachment_sizes(max 10 files, 6 MiB each, 10 MiB total); paths must canonicalize underPILOTWAVE_ATTACHMENT_ROOTS, no symlinks, no/proc|sys|dev|etc. - Backpressure: the worker is the authority — there is no producer-side flood guard. Monitor queue depth and shed load (429) in your view before enqueuing.
Development
cp .env.example .env
just pre-install-check
just sync
just dev-up # Postgres 18 + Mailcrab
just migrate
just test # pytest (33) + cargo test (84)
just lint
just run-worker -- --fg
just benchmark # memory benchmark, writes benchmark/results/
just build # maturin wheel with musl binary
Upgrading Postgres major versions needs a fresh volume: docker compose down -v && just dev-up.
Layout: python/ (Django app) · rust-worker/ (binary) · contracts/ (boundary contract) · docs/ (design docs) · benchmark/ (RSS harness) · example/ (demo app) · compose.yaml (dev only).
Docs entrypoint: docs/README.md. Contract: contracts/CONTRACT.md.
License
MIT — see LICENSE.
Metadata
Release files for pilotwave 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pilotwave-0.2.2.tar.gz | 79.2 kB | With provenance | Details for pilotwave-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pilotwave-0.2.2-py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.whl | Python 3 | none | Linux glibc 2.5+ x86-64 | Details for pilotwave-0.2.2-py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.whl |
Total release size: 1.9 MB
Release files / pilotwave-0.2.2.tar.gz
| Download URL | pilotwave-0.2.2.tar.gz |
|---|---|
| Size | 79.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03627f251ee75fb097971458790049571fdb7a58576a729d59d5fb97ced76032
|
|
BLAKE2b-256 checksum How to use checksums |
2c0ef9a3cf70abc8872f7e64a80756a13443a9142d0dc6b54588509a3a48f12d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / pilotwave-0.2.2-py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.whl
| Download URL | pilotwave-0.2.2-py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | Linux glibc 2.5+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
d48d9570d353ae4eec519ea370b55618d8e960931e8b1c4d5ae1f03cebbb6d47
|
|
BLAKE2b-256 checksum How to use checksums |
dd394a03a7af62ea390a990f2f409428051d08703f31c35bde8d8bf132facd5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for pilotwave 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pilotwave-0.2.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.