R0.2.3 · Valkey under the Exchange Platform — dive 3
The reserved tier.
The tier this module once placed in reserve is no longer a reservation. EchoMQ is
shipped, owned-protocol code: echo/apps/echo_mq, the BCS 2.0 Valkey-native bus —
born braced, born branded, born declared — and the convergence target of the EchoMQ program.
Grounding: docs/echo_mq/emq.roadmap.md (the program) · emq.design.md (the protocol canon) · content/bcs3.3.md (the claim script) · bcs3.1.md + bcsA.md (the slot figures) — every figure verbatim from a committed record.
echo/apps/echo_mq; the
frozen v1 line is the push source it absorbs.Static verdicts — the push source → echo/apps/echomq, frozen
at 1.3.0, dissolves when the movements complete · the convergence target →
echo/apps/echo_mq, version 2.0.0 · the consumer → the Exchange
Platform (docs/exchange/) · the engine → Valkey, the only engine named.
The tier, built
emq.roadmap.mdThe earlier life of this page held a seat open: a multi-runtime layer the platform reserved for a bus
to grow into. The program has since filled the seat with code. echo/apps/echo_mq is the bus
— EchoMQ.*, lib-only, version 2.0.0 — re-derived from first
principles by the Branded Component System and shipped as measured, rung-gated code: born braced
(emq:{q}:), born branded (JOB ids gated at the key builder), born declared
(every Lua key declared or grammar-derived).
The fork behind it was ruled to happen exactly once. The v1 line carried two structural flaws that
rode its wire and could not be fixed under compatibility — operand keys built from an
ARGV prefix inside script bodies, and an open keyspace with no total parse — so the
line froze, and the new bus was born under the v2 laws instead of patched toward them. EchoMQ broke from that
v1 line, now frozen at 1.3.0. That frozen line, echo/apps/echomq, is
the program’s push source: its capability surface is absorbed over the
program’s movements, and the app dissolves when the movements complete.
The tier also has a named tenant now. The Exchange Platform (docs/exchange/)
is the program’s named consumer: its specification records settlement, notifications, end-of-day
reporting, and reconciliation as EchoMQ.Jobs work drained by EchoMQ.Consumer
and shaped by EchoMQ.Lanes.
One atomic move, the real one
content/bcs3.3.mdThe defining move of the bus is claiming the next job to work, and the script is committed — quoted verbatim:
local popped = redis.call('ZPOPMIN', KEYS[1])
if #popped == 0 then return {} end
local id = popped[1]
local jk = ARGV[1] .. id
local att = redis.call('HINCRBY', jk, 'attempts', 1)
redis.call('HSET', jk, 'state', 'active')
local t = redis.call('TIME')
local now = t[1] * 1000 + math.floor(t[2] / 1000)
redis.call('ZADD', KEYS[2], now + tonumber(ARGV[2]), id)
return {id, redis.call('HGET', jk, 'payload'), att}
One script, one claim: ZPOPMIN pops the lex-oldest pending id — score-zero means
lex order is mint order — HINCRBY increments attempts, HSET
marks the row active, and TIME stamps a lease on the server’s
clock into the lease-scored active set. Atomic execution means the pop, the increment, and
the lease land together or not at all. The quiet center is one integer doing two jobs: the
attempts counter, incremented inside the claim, is the fencing token every
other transition verifies — a right token retires the row; a stale token answers
EMQSTALE.
Static verdicts — claim → ZPOPMIN the lex-oldest, HINCRBY attempts to 1,
lease at TIME+40 ms · complete with the right token → retires the row, nothing remains ·
complete with token 99 → EMQSTALE, the row survives · the committed round trip
reads one job, two lives, one counter.
Notes on ValkeyThe clock inside the script is the server’s:
TIME reads a frozen value for the script’s duration, and scripts replicate by effects
— which is what makes a server-clock lease inside a write script sound, immune to client skew —
valkey.io/topics/replication.
complete with the right token retires the row -- nothing remains
EMQSTALE; the lease holder's work survives the zombie's complete
one job, two lives, one counter
One queue, one slot, by grammar
content/bcs3.1.md F5 · bcsAThe claim script touches two keys — the pending set and the active set — plus the job row
built from a declared prefix. What makes that multi-key move legal forever is the grammar: the hashtag
is the queue name, so every key of one queue answers one cluster slot. The connector gate holds
the same arithmetic client-side — slot 105 == 105 against 8507 for the
payments queue, with the CRC16 specification vector answering 12739 (bcsA). Per-queue
transition scripts are single-slot legal on the clustered day by grammar, not by review.
pending, active, meta, and the job row of {orders} all answer slot 105; {fills} answers 4165
The protocol is the contract
bcs3.2 · bcs3.3 · emq.roadmap.mdThe reason one bus serves more than one runtime is not a port. It is that the protocol is the
contract: the closed emq:{q}:<type> grammar plus the atomic Lua bundle. The
same source string yields the same SHA1, and any client on any runtime that loads it speaks identical
semantics — the same pop, the same token mint, the same lease arithmetic. A Go consumer is a loop
around the same EVALSHA calls the Elixir reference makes (bcs3.3); the program roadmap names
a Go sibling in its cross-runtime fleet, and a Node runtime is strictly proposed — not asserted.
Reserve a seam for the bus, then fill it with a contract rather than a codebase: a closed grammar and a script bundle any conforming runtime can load.
EchoMQ at echo/apps/echo_mq over Valkey — the convergence target the program
extends rung by rung, with the Exchange Platform draining it.
The tier stopped being a reservation the day the bus shipped as owned code: one grammar, one bundle, one fence — and a program that absorbs the frozen line rung by rung.
The doors
live routes · living statusThis closes R0.2. The depth on the far side is taught by two courses — both doors are live routes.
EchoMQ — the protocol, in depth
The program builds the extension ladder rung by rung: emq.0 lands the BCS migration; emq.1 (specced) is the scheduler + retry vocabulary; the families beyond — migration path, parent/flow, groups, batches, lifecycle, the cache deepened, conformance — are planned.
/bcsThe Branded Component System
The architecture the bus shipped inside — every figure from a frozen transcript.
…/overview/patterns-become-protocolR0.3 — Patterns become protocol
The next module: why the worked examples hold for any runtime that connects — the protocol, owned.
References
sources · relatedSources
- Redis — ZPOPMIN — the pop that claims the lex-oldest pending id.
- Redis — HINCRBY — the increment that mints the
attemptsfencing token. - Valkey — Replication — the frozen-
TIMErule and effects replication behind the server-clock lease. - Valkey — Programmability — atomic script execution: the pop, the increment, and the lease land together or not at all.
- Valkey — Cluster specification — hash slots, CRC16 modulo 16384, and hash tags as the same-slot mechanism.
Related in this course
- R0.2 · Valkey under the Exchange Platformthe module hub — the pager loops back here
- R0.2.2 · The two rolesthe previous dive; the bus role
- R0.3 · Patterns become protocolthe next module; the contract for any runtime
- /echomqthe protocol in depth, rung by rung
- /bcsthe architecture, with the frozen transcripts