Real-time Chat System
Advanced
50 XP
You're trying this as a guest: your result shows here but isn't saved.
Sign in
Design a scalable real-time chat system — the kind that powers Slack, Discord, and WhatsApp.
This requires WebSockets for real-time communication, a message queue for reliability, caching for performance, and careful thought about what happens at scale.
The brief
Design a chat system that supports 100,000+ concurrent users.
Required components:
- Load Balancer — Distributes connections across multiple servers.
- WebSocket Server — Maintains persistent connections with clients.
- Message Queue — Ensures messages are delivered even if a server is busy (e.g., Redis Pub/Sub, RabbitMQ).
- Chat Service — Business logic: message routing, group management, read receipts.
- Database — Persistent message storage for chat history.
- Cache — Hot data: recent messages, user presence (online/offline), typing indicators.
Show these flows:
- User A sends a message to User B (real-time delivery)
- User B comes online and loads message history (cache -> database fallback)
- A group message is sent to 50 members (fan-out pattern)
Scale considerations:
- What if one WebSocket server goes down?
- How do you handle messages when the recipient is offline?
- How do you prevent the database from being overwhelmed?
To pass
- A component named "Load Balancer"
- A component named "WebSocket Server"
- A component named "Message Queue"
- A component named "Chat Service"
- A component named "Database"
- A component named "Cache"
- At least 7 connections between components
Need a hint?
- WebSockets keep a persistent connection — the server can push messages without the client asking.
- The message queue decouples sending from receiving — if a server is busy, messages wait in the queue.
- Use Redis for presence (who's online), recent messages cache, and pub/sub between WebSocket servers.