B2.6.2 · dive 2 of 3 · module B2.6
A native codec with a pure fallback.
EchoData.Native accelerates the hot codec and hash with a Rust core through a C shim; when the NIF is absent the pure Elixir path serves, with identical results. One module routes between them.
The idea
echo_data · native.ex, branded_id.exThe codec and the hash are the hot path — every id crossing a boundary is parsed, and many are hashed to place a key — so EchoData.Native offers a native core for exactly those operations: decode, decode_hash, encode, and hash32, backed by Rust through a C shim. It is optional: when the shared object is absent, every call falls back to the pure Elixir implementations, so the library runs with or without the native build.
One module owns the codec, and it chooses the path. EchoData.BrandedId checks Native.loaded? and routes to the native function or the pure one, and loaded?/0 reports which is active; everything else — the tries, the maps, the persistence type, the web layer — calls through BrandedId and never sees the difference. The acceleration is a swap behind a single door, not a change to any caller.
Codemojex runs the pure path in development and the native path in production from the same code, and a node’s log records which served. A move is gated and a key is placed at native speed where the build is present, and the game still runs unchanged on a machine where it is not — the hot path made fast where it counts, correct everywhere.
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 id the codec encodes and hashes, the same on every path
- The Go Blog — Share Memory By Communicatinga boundary that admits a message, never a reference
- Erlang/OTP — the gen_server behaviourthe process boundary the gate stands at
Related
- BCS — the course homethe law, the id anatomy, the chapter map
- Echo Persistencethe durable floor beneath the bus