jonnifyechomq

← 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

mint time → tail — newest from to

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.

built page ready to read

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 and the consumer group are ready to read; retention & the archive is on the build front, added as its pages land.

References

Sources

Related in this course