WorkflowsNotification
Notification Working Principle
Principle-based behavior of surface-scoped notifications, state transitions, fanout, and suppression.
Notification Working Principle
1. Single Event, Multi-Surface State
A notification event is stored once, with per-surface state in statusBySurface.
State model:
pendingdeliveredseenreadarchiveddeleted
2. Surface-Scoped Access
Every inbox operation is scoped by one explicit surface.
GET /notifications?surface=...GET /notifications/unread-count?surface=...POST /notifications/:id/readwith bodysurfacePOST /notifications/mark-all-readwith bodysurface
3. Realtime Fanout with Origin Dedup
Events are broadcast to all sessions in room notifications:{userId}:{surface}.
- Event types:
notification:new,notification:read,notification:read_all. - Origin session ID is propagated.
- Publisher excludes origin socket to avoid self-duplicate updates.
4. Presence-Aware Push Suppression
Producer checks room presence before push dispatch.
- Suppress
web_pushwhenweb_in_apppresence is active. - Suppress
mobile_pushonly when mobile presence signal is configured reliable.
5. Idempotency and Safety
externalRefensures dedup-safe persistence.- History replay supports reconnect.
- Document TTL cleanup is handled via MongoDB index on
expiresAt.