The Protocol · module 04
What holds the
wire together
The keys are fixed, the ids are branded, and a connection that does not match the wire is refused.
The keyspace says where, the record says what, the scripts say how.
This module teaches what keeps all three honest over time. Three guards do it: the immutable line
— the keys and field names are fixed, so the layer below the line does not change underneath a reader; the
branded-id gate — a job id is a 14-byte branded Snowflake under JOB,
checked in Lua before a row is written; and the version fence — the reserved
{emq}:version key the connector claims or verifies before its first command. All real
code, grounded in echo/apps/echo_mq and echo/apps/echo_wire.
The three guards
Three things hold the wire together, and the three dives of this module are each one of them. Pick a guard to read what it protects and the real surface that carries it — then take the dive.
What holds the wire · pick a guard
Three guards, one wire: the line keeps the substrate from shifting, the gate keeps a stranger's id out, and the fence keeps a mismatched connection from ever touching the store.
The dives
Three dives, each one guard. Each grounds in the real echo/apps/echo_mq and
echo/apps/echo_wire code — the keyspace builder, the @enqueue
gate, and the connector's fence.
The immutable line
Why L1 and L2 are fixed; change one thing below the line and read who can still find the row.
The branded-id gate
The 14-byte branded id and the EMQKIND Lua gate that admits only JOB-namespaced ids.
The version fence
The {emq}:version reserved key the connector claims or verifies before its first command.
Redis Patterns Applied
This is the depth behind R2 · Coordination in
Redis Patterns Applied: the branded-key and atomic check-then-act patterns —
atomic updates and the
one-slot move — are exactly what the
@enqueue gate and the SET … NX fence apply. There the pattern
is the door; here is the wire it guards.
Up next
This is the last module of the Protocol chapter. Close it in the workshop, or step back to the chapter to take the keyspace, the record, and the Lua layer in any order.
References
Sources
- Valkey — Documentation — the store the keys, the record, and the scripts run inside — the substrate of record.
- Valkey — SET — the
NXatomic claim the version fence uses. - Redis — EVALSHA — the load-once, run-by-SHA dispatch the branded-id gate rides on.
- llmstxt.org — The llms.txt convention — the machine-readable map format the course follows.
Related in this course
- The Protocol — the chapter this module belongs to.
- The Lua layer — the script layer the gate is the first statement of.
- The protocol below the line — the line, on a real key and script.
- redis-patterns R2 · Coordination — branded-key and atomicity, the near side of the door.