Realtime Chat System
RealtimeProductionRealtime collaborationRealtime messaging system with WebSocket channels, pub/sub presence tracking, durable message history, media uploads, and error telemetry. Use for chat products, collaborative tools, or live feeds.
Recommended for: Product teams building live messaging
Scope Notes
Intended for Product teams building live messaging at Production complexity and Realtime collaboration scope. Treat the graph as a starting shape rather than a fixed stack: keep the topology and the signals below, then swap providers to match your platform.
Review Checklist
Use Case
Team messaging apps, customer support chat, community platforms, collaborative tools
Best Fit Scenarios
- Support chat with persistent history
- Community channels with presence signals
- Collaborative apps with low-latency updates
Stack Breakdown
Architecture Layers
Components by Category
frontend
backend
database
infra
external
Why This Topology Works
The WebSocket gateway holds persistent connections while Redis pub/sub distributes messages across gateway instances. Presence is tracked separately from chat logic so each scales independently, MongoDB stores durable history, and S3 holds attachments.
Scaling Notes
Gateway instances scale horizontally behind Redis pub/sub. MongoDB shards by room and presence state is ephemeral in Redis with TTL cleanup.
Observability
Track connection count, message throughput and pub/sub lag. Gateway and Chat Service errors flow to Sentry so a broken fan-out is visible immediately.
Typical Bottlenecks
- Fan-out cost for very large rooms
- MongoDB write throughput on message history
- Attachment upload size and virus-scanning backlog
Async Flow and Reliability
Messages are written to the gateway synchronously, then fanned out through Redis pub/sub to every instance and persisted asynchronously. Media uploads are queued rather than blocking the message send.
Upgrade Path
Add authentication on the WebSocket handshake, a per-user rate limiter, and a push provider for offline recipients; then move attachment bytes to a presigned direct-to-S3 upload.