Design a chat system for a 50,000-employee company with 1:1 and group chats, presence and message history search.
Short answer
Use WebSocket gateways for real-time delivery with a session registry, a message service persisting messages per conversation (partitioned by conversation ID) with server-assigned sequence numbers, pub/sub fan-out to connected members, push notifications for offline users, a search index fed asynchronously, and enterprise SSO, retention and eDiscovery controls.
Detailed answer
- Scale: 50K users, ~20K concurrent, maybe 5M messages/day → modest; reliability, compliance and search matter more than raw scale.
- Components: gateway (WebSocket), auth via SSO, message service (PostgreSQL or Cassandra keyed by conversation_id + seq), Redis pub/sub or Kafka for fan-out between gateway nodes, presence in Redis with TTL heartbeats, OpenSearch for history search with permission filtering, object storage for files with malware scanning.
- Enterprise needs: retention policies, legal hold, audit, DLP scanning, data residency.
Architecture diagram
flowchart LR C[Clients] <--> GW[WebSocket gateways] GW --> MS[Message service] --> DB[(Messages by conversation)] MS --> PS[[Pub/sub]] --> GW MS --> IDX[(Search index)] MS --> PUSH[Push notifications] GW --> PRES[(Presence in Redis)]
What the interviewer expects
Real-time delivery mechanics plus enterprise compliance features.
Common mistakes to avoid
Ignoring retention/eDiscovery; polling instead of persistent connections.