Short answer: use a channel per editor room when the room is a real authorization boundary; use one filtered connection only when the server can enforce membership before every event is delivered. For an edtech editor that syncs collaborative cursors, the safer default is room-scoped authorization with short-lived tokens, server-side filtering, and an audit trail for joins, leaves, and rejected subscriptions.
The distinction is easy to miss. A cursor is low value compared with document content, but it still reveals who is present, which lesson they opened, and when they are active. In a classroom, that metadata can be personal data. The design therefore starts with trust boundaries, not transport throughput.
What are the actual invariants?
I write the decision record before choosing a broker or protocol. The invariants are these:
- A client may subscribe only to rooms granted by the authorization service.
- A cursor event is accepted only from a session that still holds that room grant.
- A reconnect cannot replay an old grant or duplicate a cursor update.
- Every grant, revoke, join, leave, and denied publish has an append-only audit record.
- Filtering happens before fan-out, never in a browser after a broad feed has arrived.
The exactly-once mindset matters even though cursor updates are usually ephemeral. A duplicate move can make a pointer jump backward; a missing leave can leave a stale avatar on screen. I use a per-session sequence number and an idempotency key made from (room_id, session_id, sequence). The consumer can discard an old sequence without pretending that the network delivered exactly once.
A token should name the room and the permitted action, with an expiry shorter than a typical lesson. The client can present that token, but it cannot be trusted to choose the room by changing a URL or JSON field. The authorization service remains the source of truth.
Should a room channel or filtered stream own security and scale?
Here is the trade-off I would put in an architecture review.
| Shape | Security boundary | Scale behavior | Operational cost | Best fit |
|---|---|---|---|---|
| Channel per room | Subscription itself carries room scope; easy to audit | Fan-out is proportional to active members in each room | More channel metadata and reconnect work | Small to medium rooms with distinct membership |
| Single channel with server filtering | One connection, but every event needs a membership check | Efficient for many tiny rooms; hot tenants can create noisy partitions | More complex filtering, backpressure, and observability | Large populations with stable, centralized policy |
A single filtered stream sounds cheaper because it reduces connection count. That is a transport argument, not a security argument. If a filter runs after a shared queue, the queue has already crossed the trust boundary. It also makes incident analysis harder: a metric saying “messages dropped by filter” does not tell me whether the drop was expected revocation, a stale token, or a programming error.
Room channels have a different failure boundary. A bad membership decision can expose one room, so the authorization check and audit record must be colocated with subscription admission. The blast radius is easier to reason about, but channel churn and uneven room sizes become real scaling concerns.
How does the critical path enforce token scope?
The following Go sketch keeps the policy in front of delivery. It is deliberately transport-neutral; the same sequence can sit behind WebSocket, WebRTC data channels, or a managed realtime gateway.
type CursorEvent struct { RoomID string SessionID string Seq uint64 X float64 Y float64 } func PublishCursor(ctx context.Context, token Token, ev CursorEvent, auth Authorizer, audit Auditor, out Broadcaster) error { if !auth.Allows(token, ev.RoomID, "cursor:write") { audit.Record(ctx, "cursor.publish.denied", ev.RoomID, token.Subject) return ErrForbidden } if !auth.AcceptSequence(ev.SessionID, ev.Seq) { return nil // idempotent retry or an out-of-order event } audit.Record(ctx, "cursor.publish.accepted", ev.RoomID, token.Subject) return out.ToRoom(ctx, ev.RoomID, ev) } The important line is not ToRoom; it is the authorization check that binds the token subject and action to the event room. In production I would also cap coordinate ranges, attach a server receive timestamp, and emit counters for denied publishes, stale sequences, fan-out latency, and active members per room. Those metrics expose a very different problem from raw socket count.
For a filtered stream, the equivalent check must run on every event path, including replay, recovery, and cross-region forwarding. Caching membership is reasonable, but the cache needs a bounded lifetime and an explicit revoke path. Otherwise a student removed from a class can continue seeing presence updates until a TTL expires.
Why does the rejected design still have a valid use case?
I would reject a client-selected “subscribe to everything, then hide rooms in JavaScript” design. It fails the confidentiality test, increases bandwidth, and makes compliance evidence weak because the browser becomes part of the policy engine. It is valid only for public, non-personal telemetry where every event is intentionally world-readable. That is not a classroom editor.
Policy first.
I would also avoid a channel per cursor. Cursor identity is not a durable resource; making it a routing key multiplies metadata and complicates garbage collection. Room is the useful unit because membership, retention, and audit review are already defined there.
The catch is that room channels are not suitable when a tenant has millions of tiny, short-lived rooms and a strict connection budget. In that case, keep one authenticated connection, partition the server queue by tenant, and perform authorization before enqueueing to the shared stream. If the policy engine cannot provide that pre-enqueue decision, stick with room channels even if they cost more operational work.
Testing, rollout, and compliance limits
Security tests should try to publish room A events with a room B token, replay a revoked token, and race a revoke against reconnect. The revoke race deserves a concrete timeline: a student opens a lesson, receives a room grant, loses enrollment, and reconnects while an old cursor is still buffered. The server must reject the new admission, discard the buffered event, and leave an audit record that ties the decision to the policy version. If the event is forwarded before the revoke is observed, the system needs a documented maximum exposure window and an alert, not a claim of perfect isolation. Scale tests should mix one room with 5,000 viewers and thousands of rooms with two viewers; average fan-out hides the hot-room behavior that usually hurts. A property test can assert that no event reaches a session unless Allows(subject, room, action) was true at admission time.
During rollout, log the authorization decision id, not the token itself. Keep audit records append-only, restrict their retention to the policy required by your jurisdiction, and document that cursor presence is personal data when it can be linked to a student. WebRTC defines browser peer-connection behavior, but it does not define your room authorization or retention policy; those remain application responsibilities.
Your mileage may vary. The right threshold depends on room cardinality, revoke latency, and whether the stream carries only cursors or richer collaboration state. I am not sure a universal connection-per-room limit exists; measure the broker's metadata overhead and recovery time with your own membership distribution before changing the boundary.
The architecture record should state the room boundary, the pre-delivery authorization point, the revoke path, and the audit evidence required to prove that no cursor crossed policy. Those claims can be tested under reconnect, replay, and hot-room load instead of being inferred from connection counts.
