Case study: live score updates
We assemble a live-score architecture and test it under failure. A normal-path arrow does not explain a reconnecting or slow viewer. We will reconcile event and byte counts, trace gateway loss, and state the complete delivery contract.
#Section 33The authoritative event walkthrough
The scorer submits an authorized command with a stable operation ID. The score service checks its expected version, commits the new score and publication intent, and assigns the next match version. A relay publishes that event to the retained stream. Topic routing sends it to gateway instances with interested viewers. Each gateway encodes the public payload and schedules it on bounded local queues.
The viewer applies the event using identity and version checks. If the product needs acknowledgement, it names the highest contiguous applied position. The durable event store remains the recovery source. The gateway’s local queue is only a short delivery buffer, so its restart changes connection ownership without destroying the accepted score.
This architecture allows the score service to continue accepting changes while some viewers are disconnected, within publication and retention limits. It does not mean every viewer sees every change promptly. Monitor stream age, gateway queue age, and client-reported applied progress to identify where the product’s latency requirement fails.
#Section 34Reconcile the complete fan-out count
The producer creates twenty events per second. Five gateways receive one hundred broker deliveries per second under the complete-interest assumption. Each gateway holding ten thousand viewers performs two hundred thousand local deliveries per second. All viewers together receive one million deliveries per second.
The broker leg carries 20,000 payload bytes per second. One gateway sends 40,000,000 payload bytes per second, and all gateways send 200,000,000. The latter equals 1,600,000,000 payload bits per second. Frame, encryption, transport, retransmission, and acknowledgement overhead are separate; none should be silently claimed as included.
Every multiplier names a recipient set. If only some viewers follow a match, use that match membership instead of all service viewers. If the producer emits different match streams, sum their individual event-rate times viewer-count products. Multiplying all events by all viewers incorrectly assumes every user subscribes to every topic.
The memory exercise assumes sixteen KiB of connection state, giving 819,200,000 bytes across fifty thousand viewers. Per-client queues and runtime overhead are additional. A real capacity decision needs a test with the actual message mix, TLS, churn, and slow-client policy. This chapter’s values teach counting and bottleneck identification.
#Section 35Gateway failure has a recovery trace
Gateway A fails. Its ten thousand viewers lose connections. Healthy gateways continue their local deliveries, while disconnected clients back off and retry. A sixth provisioned gateway leaves five surviving instances, matching the connection-count assumption. Admission also checks handshake, replay, and final egress capacity.
A reconnecting viewer sends its last applied version. If the gap remains retained, the gateway replays the missing suffix and transitions to live delivery without a subscription gap. If the cursor is too old or local state is lost, it supplies a versioned snapshot and tail. Repeated events across the transition remain harmless under the reducer’s rule.
The failure exercise must include repeated and missing versions, expired cursors, stale presence, and a simultaneous slow-client backlog. Restarting a gateway and seeing a socket open proves only part of recovery. The visible score must converge to the authoritative version under every declared branch.
#Section 36The complete interview contract
For Heron, choose server-to-viewer SSE or bidirectional WebSockets according to the product interaction. Give match-local authoritative versions, stable event IDs, retained history, and a versioned snapshot API. Route each public event only to gateways with interested viewers. Each gateway owns bounded socket queues and explicit slow-client behavior.
The design must state connection admission, heartbeat deadlines, presence meaning, drain behavior, reconnection backoff, replay limits, credential renewal, authorization revocation, and user-visible stale-state behavior. These are operational parts of the protocol. They are not optional details after drawing the stream and gateway boxes.