Reconnect and replay
We treat disconnection as an ordinary state transition. Retrying a socket cannot recover an unknown gap by itself. We will build cursors, bounded history, snapshot catch-up, and reconnect admission with duplicate-safe application.
#Section 25A reconnect carries progress
The viewer last applied version 101 and reconnects after five seconds. The service should not merely send whatever happens next. A resume cursor identifies the last accepted position or state version under a stream’s declared ordering. The client sends it while opening or subscribing so the service can supply later history.
At twenty events per second, a five-second illustrative gap contains one hundred events. Their payload totals 20,000 bytes at 200 each. Replay is a different workload from current live delivery, so reserve capacity for it. A widespread outage can make many clients request the same history at once.
The cursor should represent applied progress if application effects matter. A cursor advanced when bytes arrive but before the reducer succeeds can skip an unapplied event after a crash. If the client cannot persist progress, a new session may start from a snapshot. Define cursor authenticity, scope, expiration, and permissions; do not let a forged cursor access arbitrary retained streams.
#Section 26Retention determines the recovery horizon
Heron’s event log stores twenty 200-byte events each second. One hour contains 14,400,000 payload bytes, and one day contains 345,600,000. Retention is the policy deciding how long or how much history remains available. Its recovery purpose is to bound which cursors can be replayed.
A client whose position precedes retained history cannot receive a complete delta replay. Return an explicit cursor-too-old outcome and fetch a current versioned snapshot. Do not silently begin from the earliest retained event because the client may apply that tail to an incompatible older state. Completeness is part of cursor validity.
A reconnect service should check the cursor against the earliest retained position before promising a replay. If retention advances during the transfer, the chosen read must hold a compatible history boundary or detect the loss. Otherwise it can start a replay that silently becomes incomplete. Cursor validation and the actual replay view need a coherent relationship.
Retention cost also includes replicas, storage format, and cleanup. If event deletion is required for privacy, a durable replay log needs its own data-retention controls. A day of payload is not a complete disk budget. State the difference between logical history, physical copies, and backup retention.
#Section 27Snapshot plus tail needs a consistent version
A late viewer can fetch a 2,000-byte current score snapshot instead of replaying a long history. The snapshot carries version . The client then applies only events after , buffering or rejecting earlier ones. The snapshot and event versions must refer to the same authoritative update sequence.
For the illustrative five-second gap, a snapshot plus one hundred event payloads totals 22,000 bytes. This is not always cheaper than replaying the gap alone; its value is a known starting state and repair of a lost or expired base. A new viewer might need only the snapshot and events occurring during its fetch rather than the entire missed interval.
Corrections and snapshots need clear reducer semantics. A delta must not be applied twice because it appeared in both the snapshot and the replayed tail. Compare its version against the snapshot boundary. If the source cannot provide a compatible position, use a capture protocol that establishes one rather than guessing from clock time.
#Section 28Reconnect with jitter and admission limits
A gateway outage closes fifty thousand connections. If they all reconnect immediately, handshake CPU, authentication, registry writes, and snapshot reads can fail together. Reconnect backoff delays repeated connection attempts after failure. Jitter spreads those delays so clients do not retry on the same clock edge.
Spreading fifty thousand first attempts uniformly across an illustrative ten-second window gives an expected five thousand attempts per second, not a strict per-second bound. Random variation still creates bursts. A server admission limit and a queue or retry response provide the enforceable capacity boundary.
Reset backoff only after a sufficiently stable connection under a declared rule. Otherwise a flapping link can repeatedly regain an aggressive initial retry rate. Bound replay per client and globally so recovery does not starve healthy live delivery. After an outage, track lag and admission success, not only the number of established sockets.