← the depth behind redis-patterns R5 · Streams & Events
The Bus · module 04
Time is the address
Read the log as it stood at a moment — because the order is the mint, an instant is an exact position.
Module 03's consumer group reads the log forward: new entries, as they arrive.
This module reads it backward in time — a historical window selected by a wall-clock
instant. What did the log look like between 14:30 and 14:32? is a single bounded read. It works because
the stream is ordered by mint: a %DateTime{} is not something to scan
for, it is an exact id position. So a time window is a range read, not a scan
— read_window/6 for a closed [t0, t1],
read_since/5 for an open [t0, ∞), both computing their
XRANGE bounds host-side. Zero new Lua; the whole feature is id-math over
a read that already shipped. It is all real code.
A window is the bounds
Every entry id is "<ms>-<seq>" — a millisecond and a 22-bit tail. So a
time window [t0, t1] compiles to a pair of id bounds, and the read returns exactly the
entries inside. Drag the window across the mint-ordered log below: the readout shows the two bounds it becomes
and which entries fall in. Toggle to the open [t0, ∞) form and the upper bound
switches from maxid_ceil(t1) to +, the stream top.
A mint-ordered log · drag the window
The window is the bounds; the bounds are exact; the read is XRANGE. A
%DateTime{} never scans the log — it addresses it.
The dives
Three dives: the address arithmetic, the two reads it composes, and the three things you do with them. Each
grounds in the real echo/apps/echo_mq code —
EchoMQ.Stream.read_window/6, read_since/5,
minid_floor/1, maxid_ceil/1 — no new Lua.
Time is the address
The id math: minid_floor/1 the half-open lower edge, maxid_ceil/1 the inclusive upper inverse — exact because the stream is mint-ordered.
The two reads
read_since/5 the open window, read_window/6 the closed one — both delegate to the byte-frozen read/6; the inverted window raises before the wire.
Backtest, audit, debug
One read, three questions — worked on a codemojex round's GES activity feed, replayed over its open→settle window.
Redis Patterns Applied
This is the depth behind the Redis Patterns Applied chapter that doors here:
R5 · Streams & Events — the time-range read over
an event log, the event-sourcing replay, and the audit query, made concrete on the wire as id-math over
XRANGE. There the pattern is the door; here is the address arithmetic.
The live log, and the door past it
A mint-instant read covers the live log — the entries still resident on the stream.
Deep history beyond it — what a retention policy has trimmed — is not lost: it folds to the durable
floor, and the archive's merge-read serves archived ∪ live as one mint-ordered stream. That is the
next module's surface, and the Bus pillar's door to Echo Persistence —
retention bounds the live log, and EchoStore.StreamArchive folds what it trims to the
durable EchoStore.Graft floor.
The rest of the pillar
Time-travel is one reading of the retained log. The consumer group before it reads the live tail forward; retention & the archive after it bounds the log and folds what it trims to disk. Beneath them all, the stream log is the writer whose order theorem makes the mint instant an exact address.
The stream log
The append-only writer and the order theorem that makes time an exact address.
Consumer groups
The reliable forward read: at-least-once, resumable, idempotent on the branded id.
Retention & the archive
Bound the live log, then fold the trimmed segments to the durable Graft floor — the door to persistence.
The Bus
The pillar landing: the two surfaces over one wire, and all of its modules.
The stream log and the consumer group are ready to read; retention & the archive is on the build front, added as its pages land.
References
Sources
- Valkey — XRANGE — the range read both time-travel functions delegate to.
- Valkey — Introduction to Streams — the
ms-seqentry id the bounds are expressed in. - Valkey — Cluster specification — the
{q}hashtag co-locates a queue and its stream on one of 16384 slots. - Lamport — Time, Clocks, and the Ordering of Events — the order a mint-instant read reads by.
Related in this course
- Time is the address — the floor/ceil id math.
- The two reads —
read_since/5andread_window/6. - Backtest, audit, debug — the three use cases, worked on codemojex.
- The stream log — the order theorem that makes the address exact.
- The Bus — the pillar landing.
- The Branded Component System · the Bus — the manuscript chapter this module realizes.