As frontend lead of an online auction web app where four teams ship live features, what shared live-update policy would you set, and how would you enforce it?
answer
- one owner for the connection
- an envelope every topic obeys
- defaults for reconnect and hidden tabs
- every topic has a catch-up read
- measure staleness, not uptime
basics
~20 sA platform-owned connection module every feature subscribes through, one event envelope with per-topic sequence numbers, shared reconnect, hidden-tab and staleness defaults, a catch-up read per topic, enforced by a build dependency rule and staleness metrics.
solid answer
~50 sI'd make the live connection **platform infrastructure**: one module, owned by one team, is the only code allowed to open a WebSocket or event stream, and features subscribe through it by topic. Every topic follows one **envelope** (`topic`, `seq`, `type`, `payload`) and must ship a **catch-up read** that returns state with its sequence number. The module supplies the defaults nobody should reinvent: jittered reconnect that honours server hints, resubscribe from what is on screen, hidden-tab grace and close, and one "reconnecting" treatment. Each topic declares its expected rate and whether the server coalesces it. I'd enforce it with a **dependency rule** in the build, a review checklist for new topics, a mass-reconnect drill before big sales, and **staleness metrics** rather than socket uptime. A team can depart from it, but with a written reason and a named owner.
go deeper
Recall that several features opening their own live connections in one page multiplies connections and reconnects, and that a shared connection avoids it.
Explain the parts a shared live layer standardises: one connection, topics, an event envelope with sequence numbers, and a catch-up read per topic.
Show how defaults for reconnect, hidden tabs and staleness UI prevent the failures teams cause separately, and how a mass-reconnect drill tests them.
Own the trade-offs: central module versus autonomy, shared connection versus isolation, defaults versus tuning, with enforcement by build rule and an exception path that stays visible.
## Why a policy at all With four teams shipping live features (the lot page, the watchlist, notifications, the seller dashboard), the failure mode is predictable: each team opens its own connection with its own reconnect loop, its own idea of a heartbeat and its own "reconnecting" banner. The page ends up holding several connections per tab, a deploy triggers several reconnect storms at once, and users see one widget live while another silently freezes. None of this shows in a demo; all of it shows at closing time with 50,000 watchers. A lead's job is to make the right behaviour the easy one. ## The policy | Area | Rule | |---|---| | Connection | one live connection per tab, opened only by the platform module | | Subscriptions | features subscribe by topic through the module, never to the raw socket | | Envelope | every event carries `topic`, `seq` (per topic), `type`, `payload` | | Catch-up | every topic has an ordinary read returning state plus its `seq` | | Reconnect | module default: heartbeat deadline, capped jittered backoff, server hint honoured | | Resubscribe | from the module's registry of what is on screen, then catch-up read | | Hidden tab | module default: drop high-rate topics, grace period, close; resync on return | | Rate | each topic declares expected rate and who coalesces; client paints once per frame | | Staleness UI | one shared "reconnecting / may be out of date" treatment | | Writes | user actions go over ordinary HTTP with idempotency keys, not the live connection | ## How to enforce it A policy only on a wiki erodes within a quarter. What holds it: 1. **A dependency rule in the build.** Only the platform module may construct a WebSocket or an `EventSource`; anywhere else fails the check. This is the strongest control, because it makes the wrong path impossible rather than discouraged. 2. **A topic review.** Adding a topic means filling a short form: its envelope, sequence source, catch-up read, expected rate and coalescing. The platform team reviews it like an API change. 3. **Shared components.** The staleness banner and the "updating" row state are components the module drives, so features get consistent behaviour by using them. 4. **A drill.** Before a major sale, the team closes every connection in a staging environment at once and watches reconnect timing, catch-up read load and how long screens stay stale. ## What to measure Socket uptime is the wrong number: a connection can be up and the screen wrong. Measure what users experience, sampled: - **time stale**: how long screens show "reconnecting" or "updating", per session; - **reconnects per session** and their spread after a deploy; - **gap resyncs** per topic, which reveal ordering or delivery problems on the server side; - **catch-up read latency** at reconnect peaks. ## The trade-offs a lead owns - **Central module versus team autonomy.** A shared module is a dependency every live feature waits on. The answer is a small, stable API and a fast review, not giving each team its own socket. - **One connection versus isolation.** A noisy topic can delay a critical one on a shared connection. Server-side coalescing and per-topic rate declarations handle most cases; a feature with a genuinely different profile, such as large binary payloads, can earn its own channel through the exception path. - **Defaults versus per-feature tuning.** Heartbeat interval, grace period and backoff cap are defaults, not laws. A team can tune its topic, but the tuning is recorded where the next engineer will find it. ## Rolling it out The policy arrives on an app that already has live features, so it lands in steps. Move the noisiest feature first, usually the lot page, because it proves the module under real closing-time load. Move the others one at a time, and delete each feature's private socket code as it moves rather than keeping it as a fallback nobody tests. The dependency rule switches from warning to failing once the last private connection is gone. ## Exceptions A departure needs a written reason, an owner and a review date. That keeps the rare legitimate exception possible while making "we just used our own socket" visible rather than silent.
- A team argues the shared connection slows their release cadence. What do you do?Check whether the slowness is the module's API or the review. A stable subscribe-by-topic interface should let a team add a topic without touching module code; if reviews are the bottleneck, give the topic form a fixed turnaround. Handing them their own socket trades a process problem for a production one.
- How do you know the policy is working six months in?The dependency check still passes with no new exceptions, time-stale per session is flat or falling, reconnects after deploys stay spread rather than spiking, and gap resyncs per topic are rare. Exceptions that have passed their review date are a second signal worth reading.
- Let each team choose its own transport and reconnect logic; they know their feature best.
- Measure the live layer by connection uptime alone.
- Use a fixed reconnect delay across all clients for predictability.
- A connection that reports itself open means every screen it feeds is current.
- A shared module means no feature may ever have its own channel.