Workers
PartialThe server’s background work is everything that happens without a request waiting on it: landing
telemetry, computing calc rules, sending notifications, settling commands, holding event rule streaks
for their sustain, and pruning what has aged out. Two shapes carry it today. Telemetry arrives on the
bus, so a JetStream consumer lands it. Everything else is born as a Postgres row, so a server
tick drains it: a loop on a fixed interval. The ticks that claim work rows (calc marks,
notifications, snoozes) claim them with FOR UPDATE SKIP LOCKED, so two servers against one
database share the work, and a restart resumes where the last pass stopped.
One machinery, several consumers
Section titled “One machinery, several consumers”The telemetry consumer is the one consumer built
(messaging). It carries the exactly-once
triple every consumer here is meant to share: the stream deduplicates a batch’s Nats-Msg-Id, the
consumer double-acks, and the sink is idempotent, a batch’s receipt written in the batch’s own
transaction
(ADR-0311).
It runs as one durable per partition of the outpost’s name, each holding one batch in flight, so an
outpost’s batches land in order while the partitions land side by side
(ADR-1896).
Order matters for the property lane, whose transition guard compares a value with the series’ latest:
a lock per series stops two batches writing one value twice, but cannot reorder them. A transient
failure is redelivered after a growing delay, up to five deliveries; the consumer then gives the batch
up and records why (accounting).
The rest runs on ticks, each a goroutine of its own in internal/bus or internal/notifier, so a slow
pass of one never delays another:
| Tick | Every | What it drains |
|---|---|---|
| calc | 1 s | up to 500 pending calc marks a pass, each in its own transaction, oldest first (ADR-0148) |
| notification | 2 s | the queued notification rows an alarm transition wrote, and the snoozes past their deadline (ADR-0618, ADR-1318) |
| settlement | 5 s | commands past their settle window, then event rule streaks held for their sustain (ADR-0144) |
| rule reconcile | 1 min | event rule state against the newest samples, healing a rare race; once at start too |
| check-in age | 15 s | every claimed outpost’s checkin-age |
| orphan flush | 1 min | the orphaned-batch counts on each outpost row |
| receipt prune | 1 h | telemetry receipts older than a day |
| sample retention | 1 h | samples past their retention window (storage) |
A silent outpost produces no message, so its liveness is read rather than drained: the check-in age
timer writes the seconds since each outpost last spoke, and the seeded outpost-silent rule reads that
series like any other
(ADR-1707).
There is no projector stage: a current value is read from the latest series row
(storage), and alarm holds its own state. Two pieces of work are
deliberately not background work. Health rolls up inside the transaction
that changed it, since a rollup a hop later would record its transition at the wrong moment. Parsing
happens at the edge (collection).
Stateless and stateful work
Section titled “Stateless and stateful work”The axis that decides how a piece of work is written:
- Stateless (owner resolution, calc): the output is a function of the input, the rules and a snapshot. Order does not matter, and the write is an append.
- Stateful (the alarm lifecycle): state persists across inputs, so order matters. The alarm
transition serializes per alarm identity, the raiser’s
dedup_key(ADR-0075), and the write is a guarded upsert with a partial unique index as the backstop:alarm_open_identity_keyallows one open alarm per component anddedup_key.
Every derived sample carries its lineage on the row: provenance says where it came from (observed,
calculated, intended or declared), and a calculated row names its source_rule and the rule’s id, so its
history outlives the rule (metrics and properties).
Measuring the ticks
Section titled “Measuring the ticks”The consumer and the ticks report how they keep up on the server’s own platform component once a report window (#1628), beside the pipeline figures (messaging). Every failure count sits beside its attempts, so a loss reads as a ratio where 0 is healthy.
- Calc:
calc-pending-depthis the deepest the pending set stood at any pass in the window, marks still waiting out their debounce included;calc-served-countthe marks the window’s passes computed;calc-pass-durationa pass’s mean milliseconds. Healthy is a depth that falls back toward 0 between bursts and a pass well under its second. - Notifications:
outbox-queued-depthis the rows still queued at the window’s close, due or waiting out a retry backoff;outbox-due-agehow long the oldest due row has waited past its send time, 0 when none is due. A failing webhook holds the depth up while the due age stays near 0, since a backoff is not a wait; a due age that grows says the sender is not reaching its rows. - Settlement:
sweep-duration,sweep-countandsweep-failure-count, each at two instances,command-settlementandevent-rule. A pass that succeeds writes its failure count as 0, so Platform health reads each sweep’s failures against its passes.
These read the server’s clock against its own database, so unlike ingest lag no outpost clock is in
them (ADR-1628).
The rules that alarm on the server itself, rule-sweep-stalled among them, are on
self-monitoring.