Autopsy #10: The Multi-Tab WebSocket Storm & Backpressure Collapse
Users opening 8 tabs exhaust realtime gateway sockets and freeze the main thread during 400 msg/s bursts.
The Incident & The False Culprit
A dashboard feature PR enabled per-widget live ticker subscriptions inside useRealtimeFeed(). In single-tab local dev against a 5 msg/s mock stream, CPU usage stayed under 3%.
- T+00:00Market open triggered a 400 msg/s upstream price burst across 10,000 active browser sessions.
- T+02:00Edge telemetry recorded 80,000 concurrent WebSocket connections because power users kept 6 to 10 tabs open on the same origin.
- T+04:30RUM p95 Interaction to Next Paint (INP) jumped from 38 ms to 1,840 ms as each browser executed 3,200 `JSON.parse()` calls per second across 8 main threads.
- T+07:00A gateway node recycled, dropping 80,000 sockets and triggering a 14-minute `503` storm at the TLS terminator.
The Red Herring — Why the First Reflex Failed
On Slack, the team shipped a quick patch: setTimeout(() => reconnect(), 1000) paired with a 100 ms React setState throttle. It lowered render counts in local DevTools.
In production, it amplified the outage:
- Socket multiplication stayed intact: 8 tabs still opened 8 TLS/WebSocket connections per user.
- Main-thread parsing continued: Throttling
setStatestill executedJSON.parse()for all 400 msg/s on the UI thread before discarding updates. - Fixed-delay retries synchronized failures: All 80,000 dropped sockets reconnected in lockstep at
t + 1000 ms, pinning the TLS edge in a 503 loop.
Causal Chain Traversed
Step-by-step propagation across atomic concepts. Hover or click any step to inspect the underlying mechanism.
- 01Web APIsBroadcastChannel and Web Locks API
Coordinates cross-tab socket ownership using Web Locks and fans out frames over BroadcastChannel.
- 02Web APIsDedicated Web Workers and Transferables
Moves JSON parsing and frame normalization off the main thread into a dedicated worker.
- 03Web APIsStreams API and Backpressure Mechanics
Applies TransformStream queuing and desiredSize thresholds so slow tabs drop or coalesce stale frames.
- 04State & ArchitectureMulti-Tab State Synchronization & Leader Election
Elects a single active tab to hold the upstream WebSocket and transfers ownership on tab close.
- 05Network & PerformanceWebSockets, SSE, Reconnection Jitter & Consumer Backpressure
Enforces full-jitter exponential backoff on reconnects so gateway restarts do not trigger a thundering herd.
Five concurrency and backpressure failures compound across tabs:
- Tab fan-out: Every tab opens its own WebSocket without cross-tab coordination.
- Main-thread JSON storm:
JSON.parse()runs on the UI thread for every frame. - Missing backpressure: Unbounded
postMessagequeues balloon memory in slow tabs. - Unguarded failover & synchronized retries: Tab closes drop feeds and fixed timers trigger reconnect storms.
Failure Reproduction Lab
Use the step machine below to trace how 8 open tabs amplify a 400 msg/s burst into main-thread stalls and a synchronized reconnect storm, then step into the Web Locks + Worker Stream + Full Jitter architecture.
Multi-Tab WebSocket Storm vs Leader-Elected Backpressure
Trace how 8 open tabs amplify a 400 msg/s burst into main-thread stalls and reconnect storms, and how Web Locks + Worker Streams + Full Jitter isolate it.
Each tab opens its own WebSocket. At 10k active users with 8 tabs each, the gateway holds 80,000 concurrent sockets.
const ws = new WebSocket('wss://rt.example.com/feed');
// x8 per browser- openTabs
- 8
- socketsPerUser
- 8
- gatewayConnections
- 80000
- mainThreadBlockedMs
- 14
Layer-by-Layer Dissection
Cross-Tab Ownership Eliminates Duplicate Sockets and UI Parsing
Without BroadcastChannel and Web Locks API, eight same-origin tabs instantiate eight independent WebSocket connections. Acquiring navigator.locks.request('ws-leader', ...) restricts upstream socket ownership to one tab while BroadcastChannel fans out normalized deltas to followers:
- Leader tab: Holds the single
rt-socket-leaderlock and broadcasts parsed deltas. - Follower tabs: Subscribe to
BroadcastChanneland wait in the Web Locks queue for automatic failover.
Moving socket ownership to one tab still leaves JSON.parse on that leader's UI thread. Delegating socket I/O and frame decoding into Dedicated Web Workers and Transferables isolates the main thread from 400 msg/s allocation spikes and GC sweeps.
Worker Parsing Feeds Stream Backpressure
A dedicated worker protects the UI thread, yet an unbounded postMessage loop still floods backgrounded or slow follower tabs. Routing inbound frames through a TransformStream enforces Streams API and Backpressure Mechanics using controller.desiredSize and a CountQueuingStrategy:
desiredSize > 0: Forwards normalized ticker deltas downstream toBroadcastChannel.desiredSize <= 0: Coalesces or drops superseded updates instead of queuing unbounded objects in memory.
Backpressure Requires Atomic Leader Failover
When the user closes the leader tab, follower tabs lose their upstream feed unless failover is automatic. Under Multi-Tab State Synchronization & Leader Election, navigator.locks handles handoff atomically:
- Tab termination: Blink releases the held
rt-socket-leaderlock immediately on unload. - Next queued tab: Resolves its pending lock promise and resumes from the last sequence ID.
Leader Failover Connects Through Full-Jitter Backoff
Even with one socket per browser, a gateway restart drops 10,000 leader sockets simultaneously. Applying WebSockets, SSE, Reconnection Jitter & Consumer Backpressure replaces fixed timers with full-jitter exponential backoff (Math.random() * Math.min(30_000, 500 * 2 ** attempt)).
Randomized delays spread reconnect handshakes evenly across the backoff window instead of slamming the TLS edge in one wave.
Architectural Fix & Invariants
// worker.ts: Leader-locked socket + full-jitter reconnect
let attempt = 0;
function runLeaderSocket(channel: BroadcastChannel) {
const ws = new WebSocket('wss://rt.example.com/feed');
ws.onmessage = (ev) => channel.postMessage({ type: 'DELTA', payload: JSON.parse(ev.data) });
ws.onclose = () => {
const delay = Math.random() * Math.min(30_000, 500 * 2 ** attempt++);
setTimeout(() => runLeaderSocket(channel), delay);
};
}
navigator.locks.request('rt-socket-leader', () => {
runLeaderSocket(new BroadcastChannel('rt-feed'));
return new Promise(() => {});
});Architectural Invariants
- Single socket per origin: Only the holder of the
rt-socket-leaderWeb Lock opens an upstream WebSocket connection. - Zero main-thread frame parsing: All
JSON.parseand payload normalization executes inside a Dedicated Worker. - Bounded queue depth: Stream consumers inspect
desiredSizeand coalesce stale frames when backpressure activates. - Full-jitter reconnects: Every reconnect timer samples uniformly from
[0, min(cap, base * 2^attempt)]and resetsattemptonly after a stable open window.
Golden Rule: One browser equals one upstream socket; parse frames in a worker, shed load with stream backpressure, and jitter every reconnect.
Primary Sources
Last verified: 2026-11-16