B7.6.2 · dive 2 of 3 · module B7.6
Channels and PubSub.
Live updates ride a WebSocket channel fed by PubSub: the score worker publishes a scored event, every channel on that game forwards it, and the mode decides — a live room pushes at once, a blind room stays silent until the close.
The idea
codemojex · channels and pubsubLive 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 polling. The producer of those updates is the score worker from the play path: when it records a scored guess, it publishes a scored event on the internal PubSub, addressed to that game.
PubSub is what decouples the worker from the crowd. The worker does not know or care who is connected; it publishes once, and every channel subscribed to that game forwards the event to its players. A player sees their result and the leaderboard move in the same moment the worker writes it down, and the web tier holds no per-room state to make that happen.
Whether anything is pushed at all is the mode’s call. A live room broadcasts each scored guess, so the channel is busy and immediate. A blind room publishes nothing per guess — the worker records in silence and the channel stays quiet until the settlement at the close, when the result and the payouts arrive together. The same channel and the same PubSub serve both; the policy decides what crosses them.
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
- Kreps — The Log: real-time data’s unifying abstractiona scored event published once and fanned out to every connected channel
- The Go Blog — Share Memory By Communicatingthe worker decoupled from the crowd, scaling as more trees by message
Related
- BCS — the course homethe law, the id anatomy, the chapter map
- Echo Persistencethe durable floor beneath the bus