Loading...
Loading...
Client-side WebSocket resilience patterns: backoff with jitter, circuit breakers, heartbeat hysteresis, command acknowledgment, sequence gap detection, and mobile-aware timeouts.
npx skill4agent add apankov1/quality-engineering websocket-client-resilience| Rationalization | Why It's Wrong | Required Action |
|---|---|---|
| "Our users are on fast networks" | Mobile users exist. Even desktop WiFi has transient blips. | Test with throttled networks |
| "Simple retry is enough" | Without jitter, all clients retry at once after an outage | Add randomized jitter |
| "One missed heartbeat means disconnected" | Network blips last 1-3 seconds. Single miss = false positive. | Use hysteresis (2+ misses) |
| "We'll add resilience later" | Reconnection logic is foundational. Retrofitting it is much harder. | Build it in from the start |
| "5 seconds is plenty of timeout" | Mobile P99 is 5-8s. That "timeout" is normal latency for mobile. | Use 10s+ for mobile |
// WebSocket resilience pattern implementations (zero dependencies)
import {
getBackoffDelay,
circuitBreakerTransition,
shouldDisconnect,
CommandAckTracker,
detectSequenceGap,
classifyTimeout,
} from './resilience.ts';| Pattern | Detect | Fix | Severity |
|---|---|---|---|
| Backoff without jitter | | Add +/- 25% jitter | must-fail |
| No circuit breaker | Reconnect without failure counter | Trip after 5 failures, 60s cooldown | must-fail |
| Single heartbeat miss | | Require 2+ missed heartbeats | should-fail |
| No command ack | | Track pending commands, timeout at 30s | nice-to-have |
| No sequence tracking | | Track lastReceivedSequence, detect gaps | nice-to-have |
| Short mobile timeout | Health timeout < 10s | Use 10s+ for all health checks | must-fail |
| Pattern | Utility | Status |
|---|---|---|
| 1. Backoff with jitter | | Code + tests |
| 2. Circuit breaker | | Code + tests |
| 3. Heartbeat hysteresis | | Code + tests |
| 4. Command acknowledgment | | Code + tests |
| 5. Sequence gap detection | | Code + tests |
| 6. Mobile-aware timeouts | | Code + tests |
WebSocketws