Skip to main content

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.

Python 3.14 Django 6 License: MIT Postgres 18

Pilotwave is a two-part email outbox for Django:

  1. Producer (Python): your view calls mail_notification.enqueue(...) — a single Postgres INSERT via django.tasks + django-tasks-db. The request returns immediately, no SMTP in the request cycle.
  2. Worker (Rust): the static pilotwave-worker binary polls Postgres with FOR UPDATE SKIP LOCKED, sends via SMTP, marks the row SUCCESSFUL/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 by priority DESC, run_after, enqueued_at. Multiple workers can coexist.
  • Fail-closed safety. Attachment roots required (PILOTWAVE_ATTACHMENT_ROOTS, no MEDIA_ROOT fallback), header/injection checks, secret redaction, least-privilege DB roles.
  • Observable. pilotwave_heartbeat row (last_seen, counters, last_error_code), plus status / list / inspect CLI (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-worker drains the pilotwave.email queue.
  • 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 benchmark before 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 --fg under systemd/Docker with Restart=always. --bg daemon mode exists but foreground + supervisor is preferred.
  • Scale horizontally with more workers — SKIP LOCKED prevents double-claim. Expect duplicates only on crash-after-send (at-least-once).
  • Monitor pilotwave_heartbeat (key='pilotwave_worker'): alert if last_seen is stale or metadata.last_error_code is smtp_transient/smtp_exhausted.
  • Attachments: declare attachment_paths + attachment_sizes (max 10 files, 6 MiB each, 10 MiB total); paths must canonicalize under PILOTWAVE_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.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pilotwave 0.2.3
File Size Uploaded Provenance Actions
pilotwave-0.2.3.tar.gz 82.0 kB With provenance Details for pilotwave-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pilotwave 0.2.3
File Interpreter ABI Platform Actions
pilotwave-0.2.3-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.3-py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.whl

Total release size: 1.9 MB

Release files / pilotwave-0.2.3.tar.gz

Download URL pilotwave-0.2.3.tar.gz
Size 82.0 kB
Tags Source
SHA-256 checksum
How to use checksums
879c9fde4e164c7adb1e962c938c3f444fdd8076c9e408f78f5213bbe2fb2368
BLAKE2b-256 checksum
How to use checksums
b265775f632c8b3cc21ccc5346b0f0ae0c6fb41a0ee57942926e8b6dabfba923
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 26, 2026.

Transparency log

Release files / pilotwave-0.2.3-py3-none-manylinux1_x86_64.manylinux_2_5_x86_64.whl

Download URL pilotwave-0.2.3-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
cf559d3e0624f6047878ece55f8f58ad9c7c38e06b87e59c6fc198ac9eb9c1ac
BLAKE2b-256 checksum
How to use checksums
40a01d07c092c3c5d16ade81f6a182742659333bb45caeb6b7a4bde3f6a333af
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 26, 2026.

Transparency log

Security for pilotwave 0.2.3

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.

Select from 2 files

Attestation for pilotwave-0.2.3.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 26, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page