Files

21 lines
772 B
Markdown
Raw Permalink Normal View History

# ADR 0002: In-memory WebSocket hub
- Status: accepted
- Date: 2026-09
## Context
Realtime delivery (messages, typing, presence, read receipts) must reach
connected clients immediately. Options: external broker (Redis pub/sub,
NATS), Postgres LISTEN/NOTIFY, or an in-process hub.
## Decision
Use an in-process hub: `map[userID] -> connections` plus
`map[conversationID] -> subscribers`, guarded by a mutex. Membership and
read-state are resolved through a `MembershipProvider` interface implemented
by the store.
## Consequences
- Sub-millisecond fan-out, no extra moving parts.
- Presence checks (`IsOnline`) are lock-free reads used by the push notifier.
- Multi-node scaling would require a broker; the hub's publish methods are
the seam where that would plug in.