jonnifyechomq

← the depth behind redis-patterns R5 · Streams & Events

The Bus · module 02

The stream log

Where an event says a thing once and is gone, the log remembers — in the order it happened.

The stream log is the append-only record of what happened, ordered the way the store is ordered — by the branded id. One verb carries the whole idea: EchoMQ.Stream.append/4 mints an EVT record id host-side, derives the explicit XADD id from it, appends it direct onto emq:{q}:stream:<name>, and returns {:ok, branded} — the id is the receipt. What holds the log together is the order theorem: stream order, id sort, and mint order are one fact, proven by construction. When the invariant is broken, the wire tells the truth — {:error, :nonmonotonic}, never swallowed. It is all real code.

Append, and the log remembers

A stream is the same idea as an event made durable. An event is broadcast and gone; an entry appended to the log stays, ordered by the branded id, replayable by anyone at their own pace. Step the append below — mint the EVT id host-side, derive its explicit XADD id, append it direct, keep the receipt — and watch the new entry land at the tail in mint order.

The append · step the writer

mint EVT next_branded("EVT") host-side · nothing to spoof derive XADD id xadd_id/1 → <ms>-<tail22> XADD direct id <branded> · no Lua emq:{q}:stream:<name> · ordered by mint EVT EVT EVT EVT EVT EVT head — oldest tail — append → returns {:ok, branded} the receipt

One wire: an event says it once, the stream remembers — minted host-side, appended in mint order, and handed back as a branded receipt the caller keeps.

The dives

Three dives, each grounding in the real echo/apps/echo_mq code — the host-side mint and the kind door, the order theorem that holds the log together, and the claims-only id field with the minimal read-back.

built page ready to read soon on the build front

Redis Patterns Applied

This module is the depth behind the Redis Patterns Applied chapter that doors here: R5 · Streams & Events — the append-only log, event sourcing, and replay that this writer makes concrete. There the pattern is the door; here is the wire.

The rest of the pillar

The stream log is the writer. The rest of the Bus reads it: consumer groups deliver entries at-least-once, time-travel reads the log by a mint instant, and retention bounds it — folding what it trims into the durable floor. The events channel beside it is the present-tense surface the log makes durable.

The events channel, consumer groups, time-travel, and retention are the Bus's other modules, each added as its pages land. This module is the writer they all read.

References

Sources

Related in this course