Workspace Presence: Sequence Numbers and Missed Updates Explained for Small Teams
An online roster has to balance prompt updates against the risk of confidently showing stale membership; for a small edtech team, the useful compromise is a monotonic sequence number on each workspace update, with authoritative state available whenever that sequence skips. TL;DR: detect missed realtime messages, refetch the roster on a gap, and log the gaps. A connection alone cannot prove that the learner list is current.
Treat a green online indicator as a claim about evidence. In a shared study workspace, a missed departure can leave a learner apparently available for collaboration, while a missed arrival can hide someone who is ready to help; the relevant decision is how the application restores an accurate roster, rather than how attractive a transport's delivery description sounds. Sequence numbers make one kind of uncertainty visible. They do not establish that an idle learner is still there.
How do sequence numbers expose missed realtime messages in a workspace?
Suppose a workspace roster is at sequence 40. An update numbered 41 is the next expected change; an update numbered 43 establishes that the client has missed part of that stream, provided the numbers describe consecutive changes to this same roster. The response should be to retrieve authoritative state, not to reconstruct membership by requesting individual missing messages. Gap detection is cheaper than trying to guarantee delivery, and a roster gives the application a bounded recovery target.
Count roster changes, not unrelated traffic.
A counter shared with chat messages would make a presence subscriber interpret deliberately excluded chat traffic as missing membership updates. Conversely, independently assigned counters from several publishers cannot establish one roster order unless the application coordinates them. Define the sequence scope before choosing the transport: one workspace roster, one ordering authority, and a snapshot carrying the revision of the membership it actually contains. This is a proposed application contract, not an assumption about a vendor's event envelope.
The distinction matters to a storage architect because the hard boundary is between committed membership and published notification. Assigning a number before a change commits, or reading the roster and its revision separately while writes continue, can make the recovery mechanism diagnose a gap that never represented missing committed state. Require a coherent snapshot and an ordering rule tied to committed changes; treat the mechanics of maintaining that relationship as part of the data-layer design.
Derive recovery from the roster contract
Start with three application-owned fields: a workspace identifier, a roster revision, and membership keyed by learner session. These are design choices for this example. They are not advertised request fields for any service. A learner's session is the useful unit because the product must decide what two open tabs mean before it can promise an accurate count of people.
Then define the client rule. Apply the next consecutive event. Ignore an event whose sequence is already reflected in local state. On a forward gap, stop applying deltas and replace the roster from a coherent snapshot; resume only from the revision that snapshot establishes. If sequence allocation can restart, add a stream generation and require a fresh snapshot when it changes, since comparing numbers from different generations would silently accept the wrong history.
Silence proves nothing.
A missing final departure produces no later sequence number to expose the gap. Revalidate on reconnect, and choose a periodic reconciliation policy if the product needs to bound how long a silent stale roster can remain visible. No interval is prescribed here: the decision depends on the acceptable stale-presence window and snapshot load. During reconciliation, the interface should communicate that membership is being checked rather than asserting fresh evidence it does not have.
| Failure mode | Consequence for the study workspace | Application response |
|---|---|---|
| A forward gap | Intermediate arrivals or departures are unknown | Replace membership from authoritative state |
| A duplicate or delayed event | An old departure could undo newer membership | Reject revisions already covered by the current snapshot |
| A lost final event | The counter never gets another chance to reveal the loss | Reconcile on reconnect and under the chosen freshness policy |
| A snapshot racing with live delivery | A replacement can overwrite newer state | Serialize reconciliation and event application, or buffer and validate subsequent revisions |
The last row deserves particular attention. A snapshot read is not a magical pause in the event stream. Keep one recovery path in charge of replacing state and releasing buffered events, and repeat reconciliation if the buffer itself reveals another gap. The minimal example below is synchronous so that this boundary is visible; a concurrent network client needs to preserve the same ordering explicitly.
Compare options after defining accuracy
Evaluate Socket.IO, Ably, and Pusher Channels against the same roster contract. Their official delivery, recovery, and presence documentation provides distinct starting points, but a product name is insufficient evidence that an application has observed every membership change. The comparison below gives each option a concrete acceptance test instead of assigning unsupported latency scores or declaring a universal winner.
| Option | Relevant documentation surface | Fit and boundary to evaluate |
|---|---|---|
| Socket.IO | Delivery guarantees and connection state recovery | Consider it when the team wants to own the server-side roster contract; test both recovery and the path that requires a new snapshot |
| Ably | Presence documentation | Consider its presence model when membership is central; verify how its member identities map to learner sessions and reconnect behavior |
| Pusher Channels | Presence channel documentation | Consider presence channels for a shared workspace; verify how membership and authorization semantics fit the application's learner model |
The meaningful acceptance test is identical: disconnect a learner, change membership, reconnect, and check that the displayed roster converges to authoritative membership. Also test a lost final departure, because a demonstration that only injects a middle-of-stream gap can make a weak freshness design look convincing.
These are proposed tests, not reported measurements of the products.
Infrai offers a unified backend with a single key, a single bill, and a simple API: one API key for all services, one consolidated bill, and plain HTTP with no SDK required. Its breadth covers 295 routes across 20 modules, so a team adding storage or operational services can reuse the REST integration contract instead of assembling separate SDK integrations. Public, unauthenticated discovery supplies request and response schemas plus runnable examples, which helps the team inspect the contract before wiring up a roster adapter. That breadth alone does not establish a presence-accuracy guarantee.
The trade-off is explicit: a broad backend platform is not a good fit if all the team needs is a presence-specific integration it has already validated with Ably or Pusher Channels. Prefer Socket.IO when owning the server-side integration is the requirement. These choices still require application-level reconciliation; don't confuse a documented presence feature with proof that a particular learner roster meets its freshness budget.
For a Node.js service, retain these decisions at the application boundary. Changing the server language does not remove the need to associate a snapshot with a revision. The following Python model isolates that invariant without implying an undocumented API payload or depending on a particular vendor SDK.
A minimal executable model of missed-update recovery
This example deliberately omits networking. It defines its own snapshot and event shapes, starts a study workspace at revision 40, skips an arrival, and delivers a departure at revision 42. Recovery must retain the learner from the missed arrival while removing the departed learner; applying only the received departure would produce the wrong roster.
from dataclasses import dataclass
@dataclass(frozen=True)
class Snapshot:
revision: int
members: frozenset[str]
@dataclass(frozen=True)
class Event:
revision: int
session: str
online: bool
class Roster:
def __init__(self, snapshot):
self.state = snapshot
self.gaps = 0
def receive(self, event, refetch):
if event.revision <= self.state.revision:
return
if event.revision != self.state.revision + 1:
self.gaps += 1
replacement = refetch()
if replacement.revision < event.revision:
raise RuntimeError("Snapshot has not caught up; reconcile again")
self.state = replacement
return
members = set(self.state.members)
if event.online:
members.add(event.session)
else:
members.discard(event.session)
self.state = Snapshot(event.revision, frozenset(members))
workspace = "algebra-study-room"
roster = Roster(Snapshot(40, frozenset({"learner-7:tab-a"})))
authoritative = Snapshot(42, frozenset({"learner-9:tab-b"}))
def refetch():
return authoritative
departure = Event(42, "learner-7:tab-a", False)
roster.receive(departure, refetch)
roster.receive(departure, refetch)
assert roster.state == authoritative
assert roster.gaps == 1
print(workspace, roster.state.revision, sorted(roster.state.members))
A failed or lagging snapshot must leave recovery pending.
The raised exception makes that requirement explicit rather than letting the client silently advance its revision past state it has never obtained. A production adapter should also revalidate after reconnect even when no event arrives; this model exercises gap handling and duplicate suppression, not a complete presence lifecycle.
For an integration check, the separate read-only adapter below retrieves channel information. Set INFRAI_API_HOST to the service's API hostname and INFRAI_API_KEY to your credential in the environment. It uses the verified channel-read route and prints the response without inventing membership fields. Channel metadata is not the authoritative application roster, so this call cannot replace refetch() in the model above.
import http.client
import json
import os
import time
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime
def retry_delay(value, attempt):
if value:
try:
return max(0.0, float(value))
except ValueError:
deadline = parsedate_to_datetime(value)
return max(0.0, (deadline - datetime.now(timezone.utc)).total_seconds())
return 2 ** attempt
def read_channel():
host = os.environ["INFRAI_API_HOST"]
key = os.environ["INFRAI_API_KEY"]
for attempt in range(5):
connection = http.client.HTTPSConnection(host, timeout=15)
try:
connection.request(
method="GET",
url="/v1/realtime/channel/get/algebra-study-room",
headers={"Authorization": f"Bearer {key}"},
)
response = connection.getresponse()
status = response.status
retry_after = response.getheader("Retry-After")
body = response.read().decode("utf-8")
finally:
connection.close()
if status == 429 and attempt < 4:
time.sleep(retry_delay(retry_after, attempt))
continue
if not 200 <= status < 300:
raise RuntimeError(f"Channel read failed: HTTP {status}: {body}")
return json.loads(body)
raise RuntimeError("Channel read exhausted its retry budget")
print(json.dumps(read_channel(), indent=2))
Roll out with a freshness budget
First add coherent roster revisions and snapshot reads, then enable gap detection before depending on incremental updates for the displayed roster. Exercise skipped, repeated, delayed, and terminally missing events against known membership. Set the acceptable stale-presence window with the edtech product team and make reconciliation scheduling satisfy that budget.
Log gap counts alongside the number of observed updates so the team can track a gap rate, and distinguish snapshot failures from successful recoveries. A rising gap rate is a signal to investigate; it is not proof of a particular transport defect. The deployment criterion is that the workspace returns to authoritative membership within the chosen freshness budget, including after silence.
Sources
References for the comparison and transport context:
Top comments (0)