Real-time recovery and sequence consistency
Quick answer
Reconnecting restores a transport, not necessarily a consistent application state. A sequence number or server-issued revision can help detect repeated or missing updates.
How it works
For a protocol with consecutive integer sequence numbers, keep lastApplied. Ignore sequence <= lastApplied, apply exactly lastApplied + 1, and request a snapshot or replay on a gap. Validate payloads first. A snapshot must carry the revision to resume from. Use exponential backoff with a maximum delay and retry count; add jitter in production to avoid synchronized retries. Cancel pending timers on disposal and distinguish temporary errors from permanent authorization failures. Repeated actions require server-side idempotency; do not promise exactly-once transport.
Local examples
Run in a fresh browser document with local synthetic data. Actual ByteMind editor support is unverified.
(async () => {const classify=(last,seq)=>seq<=last?"duplicate":seq===last+1?"apply":"gap";console.log(JSON.stringify([4,5,6,9].map(n=>classify(5,n))));})()Expected console output:
["duplicate","duplicate","apply","gap"]A gap calls for recovery; duplicates do not advance state.
Run in a fresh browser document with local synthetic data. Actual ByteMind editor support is unverified.
(async () => {const delay=n=>Math.min(800,100*2**n);console.log(JSON.stringify([0,1,2,3,4].map(delay)));})()Expected console output:
[100,200,400,800,800]The delay grows until its cap, then stays bounded.
Common mistakes
Do not advance a revision across a gap or retry permanently unauthorized operations indefinitely.
Practice
Classify updates relative to a known revision and compute a bounded retry schedule. Explain how a snapshot repairs a gap.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Real-time recovery and sequence consistency — Knowledge Check
Apply the concept and reason about local example output.
What should a client do when it detects a missing consecutive revision?
Why use jitter in production reconnect policies?
What does an application acknowledgement add beyond a transport send?
What is the expected console output of Real-time recovery and sequence consistency example 1?
(async () => {const classify=(last,seq)=>seq<=last?"duplicate":seq===last+1?"apply":"gap";console.log(JSON.stringify([4,5,6,9].map(n=>classify(5,n))));})()What is the expected console output of Real-time recovery and sequence consistency example 2?
(async () => {const delay=n=>Math.min(800,100*2**n);console.log(JSON.stringify([0,1,2,3,4].map(delay)));})()