B7 · module 6 of 6 · The Live Surface on Phoenix
The live surface on Phoenix.
A thin JSON facade of commands and privacy-safe views, a WebSocket channel on PubSub that pushes a result the moment the worker writes it and stays silent in a blind room, and the whole game as one supervised application shipped on Fly.
Three dives: the JSON API, channels and PubSub, and production on Fly — the layer that closes the chapter, where the model and the play meet the player.
The three dives
each a leaf, the teachingThe JSON API
The surface is a thin facade, not the game. Phoenix exposes a JSON API that turns a request into a command on the systems and a read into a view, and…
B7.6.2Channels and PubSub
Live updates ride a WebSocket channel. A player joins the channel for the game they are in, and the channel is how a result reaches them without…
B7.6.3Production on Fly
The whole game is one long-lived application, and the application is the deployment. Under a single supervisor sit the database connection, the…
The module, in one law
codemojex · the thin layer over the systemsB7.6 is the live surface: the thin Phoenix layer that lets players reach the game without ever owning its state. A JSON API turns a request into a command and a read into a privacy-safe view — a guess returns an accepted status while scoring runs behind the boundary, and a player can read only their own attempts, their best total, and the leaderboard, never a guess or the secret. Live updates ride a WebSocket channel fed by PubSub: the score worker publishes a scored event, and every channel on that game forwards it, so a result and the board move arrive at once — in a live room. A blind room publishes nothing per guess and stays silent until the close. The whole game runs as one long-lived application on Fly Machines, a single supervised tree over the database, PubSub, the bus and its workers, and the endpoint, with no ephemeral job tier because the load is steady and settlement is one batch pass. Three dives: the JSON API, channels and PubSub, and production on Fly.
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
- Phoenix — Channels (soft real-time over WebSocket)the channel a player joins for a game, fed by an internal PubSub
- Erlang/OTP — the gen_server behaviourthe supervised processes the bus, its workers, and the endpoint run as
- Fly.io — Fly Machines (fast-launching VMs)the persistent, supervised app shipped and scaled as Machines on Fly
Related
- BCS — the course homethe law, the id anatomy, the chapter map
- Echo Persistencethe durable floor beneath the bus