echd — Echo on Encore · E3.3 · dive
Fair Lanes and the Metronome
Work is claimed under a lease, not taken; lanes rotate groups on a ring so no tenant starves; and the Metronome parks a consumer until its lane has work, so fairness costs no polling.
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.
The dive
docs/echo_mq/specs/emq2/emq.4/emq.4.md · emq.roadmap.md:139-149A task queue supersession has two halves, and the second is the interesting one. The first half is the claim: a job is not taken, it is claimed — one atomic move leaves the ready set and enters a lease held by the claimant, with the attempts counter as a fencing token so a stalled worker cannot act on a job someone else now owns. Failure is not loss; the job retries with backoff, and a lease that expires is reclaimed. That much is a reliable queue.
The second half is fairness without polling. One queue serves many groups, and a busy group must not starve a quiet one, so each group's pending work is a lane and the serviceable lanes sit on a ring that rotates — weighted or deficit-scheduled so each group's share is honored. The trap most fair schedulers fall into is spinning: consumers polling the ring, burning the server on every empty check. The EchoMQ.Metronome closes it by parking — a blocking pop waits on readiness and fans it to a pool of consumers over BEAM messages, so a worker sleeps until there is work for its lane, then claims. Fair share, and not one wasted poll.
Many groups, one queue
docs/echo_mq/specs/emq2/emq.4/emq.4.mdattempts counter as a fencing token so a stale worker cannot act twice. Failure is not loss — the job retries with backoff, and a lease that expires is reclaimed by a stalled-job sweep.EchoMQ.Metronome is a system: one blocking pop per queue waits on readiness and fans it to a pool of consumers over BEAM messages. No consumer spins, and no thundering herd wakes on every enqueue — a worker parks until there is work for its lane, then claims.Hover or focus a part to read it; click to pin. Without scripting, all three read in sequence.
The ring, the weight, and the block
docs/echo_mq/specs/emq2/emq.4/emq.4.mdThe fairness is not a policy bolted on; it is three concrete structures. A lane is a per-group pending set — a sorted set keyed by the group's branded name — so a group's backlog is isolated from every other's. The ring is a list holding exactly the lanes that are serviceable right now: nonempty, unpaused, under their limit. Rotating the ring, with a weight or a deficit counter per group, is what turns "many groups on one queue" into "each group gets its share," and the starvation drill exists to prove that even a flood in one lane cannot lock the others out.
The Metronome is the piece that makes fairness cheap. A naive scheduler asks every consumer to keep checking the ring, which spends the server on emptiness and wakes everyone at once when a job lands. The Metronome inverts it: a single blocking pop per queue holds the readiness signal, and when work arrives it fans that signal to a pool of consumers over BEAM messages — the runtime's own cheap mailboxes — so each parked worker is woken only when its lane has something to claim. Park-don't-poll is why the fair-lanes family scales to a multi-tenant bus without a busy loop anywhere in it.
The rule
one line to carryThe fairness rule — work is claimed under a lease, and lanes rotate on a ring so no group starves and no consumer polls. A claim is an atomic lease with the attempts fence and backoff on retry; the EchoMQ.Metronome parks a consumer on a blocking pop until its lane has work, then fans readiness over BEAM messages — fair share without a busy loop.
Doors
the fair-lanes family, in depthEchoMQ — the protocol, in depth
The claim, retry, and groups families: the lease and attempts fence, the lane sets, the ring, and the Metronome as a system.
the ring, exact — weighted and deficit rotation, and the starvation drill.
/redis-patternsRedis Patterns, Applied
Reliable queues and flow control as patterns: the atomic claim, the fencing token, and blocking over polling.
block, don't spin — why BLPOP beats a poll loop.
References
sources · relatedSources
- Valkey — BLPOPthe blocking pop the Metronome parks on, so a consumer waits without polling
- Valkey — Data typesthe sorted-set lanes and the list ring the fair rotation is built from
Related
- E3.3 — Jobs Supersede Cron and Queuesthe module this dive turns
- batches-and-locksthe next move: claiming and locking in bulk
- the-braced-keyspacethe server clock the lease is stamped by