Appearance
Namespace room names with tenant or org scope so realtime events never cross tenants.
NestJS·Realtime & Streaming·Medium·Since 2026-05-01
nestjs-realtime-transport-namespaced-rooms
A room in socket.io or a topic in a message broker must include the tenant. room: doc-123 is wrong. room: org-456:doc-123 is right.
socket.io
room: doc-123
room: org-456:doc-123
client.join(`doc-${docId}`); this.server.to(`doc-${docId}`).emit('update', data);
// libs/shared/backend-realtime/src/lib/rooms.ts export function docRoom(orgId: string, docId: string) { return `org:${orgId}:doc:${docId}`; } client.join(docRoom(user.orgId, docId)); this.server.to(docRoom(user.orgId, docId)).emit('update', data);