B1.3 · dive 4 of 4 — the entry-id injection
The id carries its window.
Stream entry ids are millisecond-sequence pairs, range-queryable by time because the id
carries it. The injection unix_ms(snow) dash low-22-bits(snow) is
order-preserving — carrying the contract into the entry id costs nothing and buys exact replay
windows.
Measured on 200,000 entries per stream against Valkey; the figures are verbatim from streams_bench.out. EchoMQ 3.0 plans Streams with PubSub — this is the groundwork that plan stands on.
unix_ms(snow), a dash, the low 22 bits.The entry id
content/bcs1.3.md · The streams horizonA stream entry id is a millisecond-sequence pair, range-queryable by time because the
id carries it, under the same monotonic top-id law the contract's minter obeys. The injection
unix_ms(snow) dash low-22-bits(snow) is therefore order-preserving: the
snowflake's high bits are the milliseconds, and the low 22 bits — node and sequence — break ties within
the millisecond the same way on both sides of the mapping.
Measured
bench/valkey-id/streams_bench.out# streams: Valkey, 200,000 entries, one 8B field/value pair each s_auto entries=200000 bytes=4174928 per-entry=20 s_brd entries=200000 bytes=4161888 per-entry=20 window [+10ms, +20ms) via branded-derived ids: 40960 entries (expected 40960) first id in window: "1781000000010-28672" (low 22 bits = node 7 << 12 | seq 0 = 28672)
Explicit branded-derived ids cost the same 20 bytes per entry as XADD *
auto-ids, and a ten-millisecond window addressed purely by id arithmetic returned its predicted 40960
entries. Carrying the contract into the entry id costs nothing.
The window arithmetic
streams_bench.out · vectors per content/vectors.jsonWhat the injection buys: exact replay windows addressed by the same min_for
arithmetic every runtime already implements — a half-open pair of instants becomes a half-open pair of
entry ids, with no second mapping to maintain. The buttons verify the bench's facts live:
The recipes
content/bcs1.3.md · HowThe fleet guarantee is that two runtimes shaping the same key produce the same bytes — which the canon's conformance suites already prove for the branded payload, leaving only the envelope to discipline:
# Elixir — the connector side
job_key = "emq:{" <> queue <> "}:job:" <> EchoData.Snowflake.next_branded("ORD")
stream_id = "#{EchoData.Snowflake.unix_ms(snow)}-#{Bitwise.band(snow, 0x3FFFFF)}"
// Go — the consumer side
jobKey := "emq:{" + queue + "}:job:" + brandedid.MustEncode("ORD", snow)
streamID := fmt.Sprintf("%d-%d", brandedid.UnixMs(snow), snow&0x3FFFFF)
Same grammar, same accessors-by-contract, byte-identical keys — so the hashtag's slot
decision agrees across the fleet, and an ORD replay window computes the same range on
either side of the bus. The injection is the one stream-id scheme (INV-K4 in the chapter's spec of
record); a parallel mapping would be the second clock in new clothing.
Where the entry id meets the bus protocol itself — queues, groups, consumers — that is the EchoMQ course's depth, through the door below.
References
sources · relatedSources
- Valkey — Streams introductionentry-id structure; time ranges from the id
- Valkey — XADDexplicit ids, total order, the monotonic top-id rule
- Valkey 8.1.0 GAthe engine the streams numbers ran against
Related
- B1.3 — the module hubthe chooser, settled by measurement
- B1 — Ideas Behindthe chapter landing
- BCS — the course homethe law, the id anatomy, the chapter map
- EchoMQ — the coursethe bus whose engine and keyspace these recipes feed
- Redis Patterns Appliedstreams and sorted sets as substrate patterns