The primitive
squeueHA is a visibility timeout queue backed by SQLite. A job is published with a payload. A worker claims it — the job becomes invisible to other workers for a configurable duration. If the worker completes, it acks the job. If the worker crashes, the visibility timeout expires and the job reappears for another worker to claim.
That's it. One SQLite table, one UPDATE ... WHERE visible_at <= now() LIMIT n in a BEGIN IMMEDIATE transaction, one configurable timeout.
Three patterns, zero code changes
The same primitive, calibrated differently, covers three distributed coordination patterns:
Leader election. 1 row, N instances. Whoever claims the row holds the lease for the visibility window. When the window expires, another instance can claim it. If the leader crashes, the lease expires and a new leader is elected. No Consul, no etcd, no Raft — one SQLite row.
Work distribution (TDMA). N rows, N instances. Each instance claims its row, holds it for the duration of its time slot, then releases. With visibility tuned to slot duration, each instance gets exactly its turn. This is Time Division Multiple Access — the same pattern that radio multiplexing has used since the 1970s, standardized for GSM in 1987. Multiple transmitters share a channel by taking turns in fixed time slots. No collision possible.
Elastic overflow. Visibility shorter than processing time under load. Jobs reappear before processing completes; other instances can pick them up. The queue absorbs bursts without a separate overflow mechanism. Under normal load, single-instance processing. Under peak load, automatic work-stealing.
The TDMA discovery
I'm not a developer by training. I spent weeks trying to solve multi-instance coordination with standard tools — Consul, then Raft, then etcd. Each one added operational complexity I didn't need for what was fundamentally a simple problem: N instances, each with its own time slot, no contention, no external coordinator.
When I described the problem in those terms to an LLM, it told me the pattern already existed. TDMA — invented for radio, applied to databases. The same SQLite visibility window that handles job queues handles time-division scheduling.
The name is mine. The pattern is fifty years old.
Operational details
Exponential backoff (50/100/200ms) on SQLITE_BUSY — reduces contention when multiple instances compete for the same row. An instance that's slow on its slot sees competitors back off rather than spin.
Dead letter queue (squeueha_dead) — jobs that exceed MaxAttempts are moved to a separate table with their full history. Nothing is silently discarded.
Priority support — priority DESC, visible_at ASC ordering means interactive jobs jump ahead of batch jobs. This is the link between the queue and the management plane: a user query gets priority over a background indexation task.
PublishAt — scheduled jobs, visible only after a specified time. One column, one WHERE clause.
All of this is one Go package, CGO-free, compiling to a static binary.
hazyhaar — open research, sovereign infrastructure github.com/hazyhaar · hazyhaar.fr