B8.2 · dive 2 of 4 · Production on Fly
Valkey on a Fly machine.
The queue’s Valkey runs as its own Fly machine — io-threads to the cores, a noeviction policy, an append-only log for a one-second loss bound — with the kernel tuned away from its defaults: huge pages off, overcommit on, low swappiness.
The idea
valkey · a dedicated datastore on FlyOn Fly, the queue’s Valkey runs as its own machine, separate from the web service. The image is a pinned valkey/valkey, started with io-threads sized to the machine’s cores — one main thread executes commands, the rest feed it — a maxmemory budget, and a noeviction policy. Eviction is the wrong posture for a job store: a queue that silently drops keys is a queue that silently loses work, so memory pressure must surface as write errors and alerts. Apps reach it over the private network at echo-valkey.internal, behind a password even on the internal mesh, with auto-stop off so a machine is not reaped under a live queue.
Durability is the reason a queue chooses this engine. With appendonly on and appendfsync everysec, the volume holds an append-only log and the loss bound after a crash is roughly one second of writes, not a whole snapshot interval — and EchoMQ’s checkpoints are designed against exactly that bound. The cost is that an AOF rewrite forks, and the copy-on-write spike during the fork must be budgeted: keep maxmemory well under the machine’s RAM and schedule rewrites off-peak.
An in-memory store needs the kernel tuned away from its defaults. Transparent huge pages are turned off, because the larger pages turn a single-byte write during a fork’s copy-on-write into a large page copy and a latency spike. Memory overcommit is set so a fork does not fail when copy-on-write means little real memory is needed; swappiness is set to its lowest practical value, because a swapped page trades nanoseconds for milliseconds; and the connection backlog and file-descriptor limits are raised so a burst of clients is accepted rather than dropped.
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
- Fly.io — Fly Machines (fast-launching VMs)the Machines the codemojex release deploys to under the codemoji-phoenix app
- Valkey — Persistence (RDB and the append-only file)the appendonly everysec posture, a roughly one-second loss bound after a crash
- Valkey — Diagnosing latency issues (fork, fsync, huge pages)the kernel tuning a job store needs: huge pages off, fork and fsync latency bounded
Related
- BCS — the course homethe law, the id anatomy, the chapter map
- Echo Persistencethe durable floor beneath the bus