Repository navigation
ADR 0010: the shape of broadcast - #12
Merged
Merged
Conversation
broadcast has been in the service map since the beginning and is still a mix.exs and a .gitkeep. Its decisions live in services/broadcast/CLAUDE.md, which is where idioms belong and where architecture does not. The thing it exists to prevent is already in the code: gateway.go opens one WatchDeltas upstream per connected browser, so the simulation's fan-out is O(clients) at the process that must not be slowed by any of them — and the gateway cannot spread that load, because replicaCount: 1 is load-bearing until its economy loop is idempotent (ADR 0005). Seven decisions, the first three load-bearing: - Fan in once per node, fan out locally. If each browser still cost sim-core a stream, an Elixir hop would be pure added latency. - Interest is a grid of Channel topics; a client joins the cells it can see. Deliberately the dumbest version — the point is to have the seam before it matters. - Deltas are droppable state, and resync goes through JoinWorld rather than replayed history. This extends the posture already in grpc.rs, where a lagging subscriber is dropped rather than allowed to slow the tick loop, and explains why the ignored from_tick is not a bug to fix here. Plus: distributed Erlang between nodes rather than a fourth broker, binary protobuf rather than Phoenix's JSON default, bounded lossy backpressure, and presence deferred until a feature needs it. Records why not Kafka to the browser — a renderer wants the current state of a region with the right to skip, not durable ordered facts, and pipsim now has both kinds of feed on purpose.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Docs only. Numbered 0010 as requested — 0008 and 0009 are unused.
Why now
broadcasthas been in the service map since the beginning and is still amix.exsand a.gitkeep. Its decisions live inservices/broadcast/CLAUDE.md— which is where idioms belong and where architecture does not.More to the point, the problem it exists to solve is already in the code.
gateway.go:101opens oneWatchDeltasupstream per connected browser:So the simulation's fan-out is already O(clients), at the one process that must not be slowed down by any of them. And the gateway cannot spread that load:
replicaCount: 1is load-bearing until its economy loop is idempotent (ADR 0005). Writing this down before there is code is the cheapest it will ever be.The three decisions that carry the rest
Fan in once per node, fan out locally. One
StreamWorldupstream per broadcast node, every browser on that node served from it. This is the entire justification for the service existing — if each browser still cost sim-core a stream, an Elixir hop in the middle would be pure added latency.Interest is a grid. One Channel topic per world cell; a client joins the cells its viewport covers plus a ring. Deliberately the dumbest version of interest management — no visibility graph, no per-entity subscriptions — because the world is 48×30 tiles and the point is to have the seam in place before it matters.
Deltas are droppable state, and resync goes through
JoinWorld. This extends a posture already in the code rather than inventing one:grpc.rs:223drops a lagging subscriber rather than slowing the tick loop, reasoning that a client which cannot keep up should resync from a snapshot. It also explains whyWatchDeltasRequest.from_tickbeing ignored by the implementation is not a bug to fix here — with a snapshot endpoint and idempotent state, delta history buys little and costs retention everywhere.Then four smaller ones: distributed Erlang between nodes rather than a fourth broker, binary protobuf rather than Phoenix's JSON default, bounded lossy backpressure (drop oldest, since newer state supersedes older), and presence deferred until something needs it.
The rejected option worth arguing about
Kafka to the browser. ADR 0002 makes Kafka the fact log, so consuming it here looks natural on a diagram. Rejected because the render path does not want facts — it wants the current state of a region at 10 Hz with the right to skip. Durability, per-partition ordering, replay and retention are all cost here and none is a benefit: a browser that missed two seconds does not want them, it wants now. The payloads are the wrong shape too —
PipDiedsays what happened, a renderer needs where everything is.That distinction (fact log vs state feed) is stated explicitly in the ADR, because the two are easy to conflate and pipsim now runs both on purpose.
Also recorded: why not serve WebSockets straight from the Go gateway (it would cap the connection fleet at one replica and couple "how many can watch" to "how many buildings can be driven"), and why not per-client interest instead of a grid (it makes every message a unicast and undoes the reason the fan-out node exists).
Honest costs, in Consequences
broadcastneeds a server-streaming Connect/gRPC client in Elixir, which the tavern deliberately avoided. 🔧 chore(broadcast): raise grpc past the RCE, and commit the lockfile #7 just moved the declaredgrpcdependency to 1.0 — this makes it the first real use of it in the repo rather than a lockfile entry.mix testcurrently fails onBroadcast.Application is not available; the first commit of real code fixes it as a side effect.Status
proposed. Five next steps, ordered so each leaves something runnable — starting with the supervision tree, which alone makes the test suite work.