B4.3 · dive 3 of 3
Coherence.
An invalidation is two ids — the name and the writer’s mint-time version. Newer wins by eleven snowflake bytes; it rides a broadcast lane through a single-producer ring, or a job lane over EchoMQ.
The idea
echo_store · coherence.ex, ring.exWhen a row is written, the caches holding it must learn. An EchoStore coherence message carries exactly two identities — the cached name and the writer’s mint-time version — and nothing else. Newer wins by comparing the eleven snowflake bytes of the two branded ids: the order theorem makes those bytes lexicographically equal to mint order, regardless of namespace, so coherence needs no coordinator, no lock, and no clock but the one already inside every id. Application is idempotent — applying the same version twice answers stale the second time, so a retry or a duplicate changes nothing.
Two lanes carry that message, chosen by what a stale read costs. The broadcast lane is a PUBLISH on the table’s channel — fire-and-forget, one wire hop, at-most-once — for surfaces where a lost message costs one TTL of staleness. The job lane is an enqueue on the table’s coherence queue over EchoMQ — at-least-once and crash-surviving — for surfaces where a stale read costs money. The same drop runs in Lua on the bus, comparing the same eleven bytes, so the wire and the heap never disagree about which write is current.
The broadcast lane is served by a ring. EchoStore.Ring is the Disruptor’s shape on the BEAM: two atomics for head and tail sequences, an ETS table of preallocated slots reused by index, a single producer and a single applier, and edge-triggered wakes — one message when the ring goes from empty to non-empty, however many items then flow. When the ring is full the publish is refused and counted, never blocked and never overwritten, because the broadcast lane is at-most-once by its substrate’s contract and a counted drop preserves that where silent overwriting would not. Surfaces that cannot accept a drop ride the job lane, which does not pass through here.
The doors
the sibling coursesEchoMQ — the protocol, in depth
The bus B3 narrates, taught rung by rung: the keyspace, the Lua inventory, and the 3.0 Stream Tier — XADD, XREADGROUP, XACK — with conformance on Valkey.
Redis Patterns Applied
The substrate patterns under the bus: sorted sets, atomic Lua moves, locks, and streams — the judgement layer.
/echo-persistenceEcho Persistence — the durable floor
Beneath the volatile tiers: the Graft page engine built twice, the commit-LSN loop, and the stream archive on Tigris. Where Part I says state lives somewhere, this says where it lives durably.
References
sources · relatedSources
- King — Announcing Snowflake (2010)the time-high id whose eleven payload bytes decide which write is newer
- DeCandia et al. — Dynamo (SOSP 2007)last-writer-wins by version, here a monotone mint-time id
- Thompson et al. — The LMAX Disruptor (2011)the single-writer pre-allocated ring the broadcast applier mirrors
Related
- BCS — the course homethe law, the id anatomy, the chapter map
- Echo Persistencethe durable floor beneath the bus