B4 · EchoCache — manuscript Part IV
Cheap to read, never wrong.
Part II gave the names a home and Part III put them in motion; Part IV makes reading them cheap without making them wrong. EchoCache is a near-cache — an L1 of declared ETS tables in front of the L2 Valkey the systems already share — and its one-line case is the part's title: branded keys, local speed, bus-driven coherence.
The comparison set is real and named — Valkey's own server-assisted tracking, Nebulex's near-cache topology, Cachex beneath it — and every member shares one shape: coherence is deletion. EchoCache says something stronger — a newer row exists for this name, minted at this time — and because the version is a branded identity, newer-wins is a comparison of two names. Each module below teaches one written chapter, its committed rung quoted verbatim on the page.
The five modules
content/bcs4.1.md – bcs4.4.mdCache-Aside at ETS Speed
The declared L1 directory over L2 Valkey, three sources of one answer, single-flight fills, the
jittered clock, and the bound that degrades to pass-through. A full cache is a stat, never an error.
The rung reads PASS 6/6.
Coherence by Mint Time
The twenty-nine-byte message of two names, newer-wins with teeth, the broadcast lane and the
job-backed lane that survives a crash. Idempotence is a comparison, not a log. The rung reads
PASS 6/6.
The Single Writer and the Ring
Two atomic sequences over preallocated ETS slots, order through batches, occupancy as the gauge, and
drop as a counted refusal — never blocked, never overwritten. LMAX and the Disruptor as prior art. The
rung reads PASS 6/6.
The Lane That Remembers
The per-group SQLite journal: two memories in one file, both crash seams closed, the bus dying and
the lane replaying, coverage as compaction. The outbox empties, the memory does not. The rung reads
PASS 6/6.
The Cache Referee
The manuscript plans Nebulex's near-cache topology, Cachex, and Valkey's server-assisted tracking measured where they run — hit-path latency, the herd drill, coherence-lag distributions. This chapter waits for its prose; no comparative figure exists yet.
A module card becomes a link when its pages ship; the dives per module are fixed in the chapter spec, and the reading order is the arc above. Part IV is written through its fourth chapter — B4.1 through B4.4 are buildable, each with a frozen rung; B4.5 waits for its manuscript chapter.
The laws of the part
content/bcs4.mdPart IV states six laws and holds every chapter to them. They are the manuscript's, named here so the modules below read as applications of a rule rather than a list of features.
Declared, not discovered
Every L1 table is declared per kind with its TTL, size bound, and coherence mode; the operator enumerates every cache in the node the way they enumerate stores. A cache that appears wherever a developer was impatient is a leak with a hit rate.
One fill per herd
A miss does not stampede the L2 or the system of record: concurrent misses on a key coalesce onto a single in-flight fill, and the herd reads the one answer. The thundering-herd drill is a gate, not an anecdote.
Coherence is a message about a name
Invalidation carries the branded key and the writer's mint-time version, nothing else. Newer wins by comparing identities; there is no coordinator, no lock, and no clock but the one already inside every id.
Two lanes, named per surface
The broadcast lane rides the bus's wake fabric for latency and accepts fire-and-forget; the job-backed lane pays queue overhead to buy at-least-once when a stale read costs money. Each surface names which lane it rides.
The single writer applies the stream
Per cache, coherence application is one owner draining an ordered ring — batched, allocation-light, and race-free by construction, because a stream applied by one writer needs no locks to stay ordered.
Replay beside the bus, never WAL inside it
Decision D-2 stands: the bus remains volatile. The memory that must survive a node — provenance, checkpoints, last-applied versions — lives in per-group journals beside the consumers, and recovery replays them.
The floor under the floor
committed outputs, quoted verbatimPart IV inherits a measured floor, not a hope. The bus that carries coherence has a committed profile, the contract under its messages is a gated artifact, and the stores being cached already guard themselves — so a cache layered above them is wrong only in the benign direction: stale for a bounded moment, never a fabricated row. The four chapter rungs on file, each an executable check and a frozen transcript:
bcs_rung_4_1_check.out cache-aside at ETS speed PASS 6/6 bcs_rung_4_2_check.out coherence by mint time PASS 6/6 bcs_rung_4_3_check.out the single writer and the ring PASS 6/6 bcs_rung_4_4_check.out the lane that remembers PASS 6/6
The inherited floor is the Part III record, quoted by the preface: the bus's
end-to-end median 0.3 ms bus vs 8.8 ms rival, a parked consumer costing 0 commands
while it waits, the conformance record's fourteen of fourteen contracts hold, and the
torn-write drill landing qty 12 once, never 17 -- and the order completes. What the part will
not do is stated too: the bus gains no persistence here — D-2 stands, the journal is beside the bus, never
inside it — and Litestream is named as the off-box layer and deliberately not implemented.
Up next
built as the manuscript shipsGo, Node, Fly, Trading
Parts V–VIII — the Go and Node runtimes, production on Fly, and the trading capstone. The manuscript plans these chapters; the course builds them as the book ships.
The Bus — EchoMQ, Valkey-native
Part III — the bus this cache's coherence rides: the keyspace, jobs as entities, the Lua state machine, fair lanes, the bus meeting the stores, and the connector.
B2The Elixir BCS Core
Part II — the stores EchoCache caches: a system as an OTP application, property stores on ETS, the CHAMP forest, archetypes as data, relations as systems.
The doors
the sibling coursesEchoMQ — the protocol, in depth
The bus the coherence lanes ride, taught rung by rung: the keyspace, the Lua inventory, conformance.
/redis-patternsRedis Patterns Applied
The caching substrate under EchoCache: cache-aside, single-flight, server-side TTL and expiry.
/elixirFunctional Programming in Elixir
The Portal engine, and the umbrella where echo_data — the production identity library — lives.
References
sources · relatedSources
- Erlang/OTP — etsthe declared L1 tables: ordered traversal, protection levels, the table owned by its process
- Valkey — client-side cachingthe comparison set's coherence-as-deletion contract: forget this key, no version, no order
- Lamport — Time, Clocks, and the Ordering of Eventsthe total order newer-wins carries in the name, cashed a third time
Related
- BCS — the course homethe law, the id anatomy, the chapter map
- B3 — The Busthe bus EchoCache's coherence rides
- B2 — The Elixir BCS Corethe stores being cached
- Redis Patterns Appliedthe caching substrate under the near-cache
- Functional Programming in Elixirthe umbrella where echo_data lives