jonnify·echd /echd/bus/streams/at-least-once

echd — Echo on Encore · E3.2 · dive

At-Least-Once

A delivered entry is a recorded debt until it is acknowledged — so a consumer can die mid-work and lose nothing, and the price is that a consumer must be idempotent.

Vision · real substrate

echd speaks in the present tense over a build ladder. Every module, verb, key, and port named on this page is real; the composition into one standing platform is the vision the ladder builds.

§1

The dive

docs/echo_mq/emq.streams.md:29-42

PubSub is at-most-once: a message is handed to whoever is listening and then it is gone. If a subscriber is down, or crashes between receiving and finishing, the message is not redelivered — it was never owed in the first place. The stream tier makes the opposite promise. A delivered entry is a debt, recorded in the consumer's pending-entries list, and it is not settled until XACK. A consumer that dies between read and ack has not dropped the work; it has left it owed, and the group can collect.

That promise has a mechanism and a price. The mechanism is the pending list plus XAUTOCLAIM: entries that sit unacknowledged past an idle threshold are reassigned to a living consumer, which finishes them. The price is duplication — "at least once" can mean twice, because a consumer might crash after doing the work but before acking — so every consumer is written to be idempotent. At-least-once is not free delivery; it is a guarantee that the work is not lost, paid for with consumers that can safely repeat.

§2

One entry's life

docs/echo_mq/emq.streams.md:29-42
One entry's life · delivered, acked, or reclaimed · hover to read
one entry's life — delivered, then acked or reclaimed delivered pending list XACK → done consumer dies XAUTOCLAIM · min-idle redelivered, live XTRIM bounds the log (MAXLEN / MINID) · replay reads from any id PubSub is at-most-once; the stream tier is at-least-once
The happy path, and the debt. A consumer reads an entry and it lands in that consumer's pending-entries list. Process it, call XACK, and the debt clears. Until then the entry is delivered but not done, so a crash between read and ack cannot silently lose it.
When a consumer dies. Its pending entries do not vanish; they sit idle. XAUTOCLAIM transfers entries idle past a threshold to a living consumer, which finishes them. No heartbeat, no leader — the pending list plus an idle timer is the whole failover.
Retention and replay. XTRIM bounds the log by length (MAXLEN) or by mint time (MINID), so memory is a policy, not an accident. And because entry ids are millisecond-prefixed, a reader replays a window by id — history without a separate store, up to the trim horizon.

Hover or focus a state to read it; click to pin. Without scripting, all three read in sequence.

§3

The price of the promise

docs/echo_mq/emq.streams.md:29-42

The pending list is what makes the guarantee real, but it is worth seeing exactly what the guarantee does and does not say. It says: no entry is lost because a consumer failed. It does not say: every entry is processed exactly once. Those are different claims, and the gap between them is the window where a consumer finishes the work and then dies before its XACK lands — from the group's view the entry is still owed, so XAUTOCLAIM will hand it to someone else, and it runs twice.

This is why at-least-once is a contract on the consumer, not only the broker. The tier promises delivery; the consumer promises idempotence — that repeating an entry is safe, whether by a natural key, a dedup set, or a conditional write. The reward for holding up that end is a system that degrades honestly: under failure it does too much, never too little, and "too much" is harmless when the work is idempotent. Retention (XTRIM) and replay by mint id round it out — the log keeps as much history as policy allows, and any window can be re-read, so recovery and audit read from the same stream the workers do.

§4

The rule

one line to carry

The delivery rule — a delivered entry stays pending until acked, so a dropped consumer loses no work. XAUTOCLAIM rescues the pending work of the dead, XTRIM bounds the log, and any id replays — and the price of "at least once" is that a consumer must be idempotent, because at least can mean twice.

§5

Doors

the guarantee, in depth
§6

References

sources · related

Sources

  • Valkey — Streamsthe pending-entries list, XAUTOCLAIM, XTRIM retention, and id-range replay

Related