How would you design a real-time chat/messaging system?
Reviewed by Gurusankar M.
Short Answer
Use persistent connections (WebSocket) via a gateway layer that tracks which server holds each user's connection. Persist messages (ordered per conversation), route via a pub/sub bus to the recipient's gateway, handle offline delivery + read receipts, and design presence and group fan-out. Guarantee ordering per conversation and at-least-once delivery with dedup.
On this page
Concept Made Simple
Coffee Chat Question
βHow would you design a real-time chat/messaging system?β
Remember It Faster
Mind Map Answer
- Transport
- WebSocket + connection registry
- Persist
- ordered messages per conversation
- Route
- pub/sub to recipient's gateway
- Also
- offline delivery, presence, receipts
Think Beyond the Expected
What If?
User A and B are connected to different chat servers β how does A's message reach B?
A connection registry (e.g. Redis) maps each user to the server holding their WebSocket. A's server persists the message and publishes it to a pub/sub channel; B's server (subscribed / looked up via the registry) receives it and pushes over B's WebSocket. If B is offline, it's stored and delivered on reconnect.
Real World
WhatsApp/Slack-style chat uses WebSocket gateways + a connection registry + pub/sub routing + durable per-conversation storage; ordering, offline delivery, presence, and delivery/read receipts are the hard requirements.
Interviewer's Expectation
Keywords they're listening for:
- WebSocket + connection registry
- per-conversation ordering
- pub/sub routing
- offline delivery + receipts
- presence, group fan-out
- at-least-once + dedup
Common Mistakes
- Polling instead of persistent connections
- No connection registry for cross-server routing
- Ignoring offline delivery / ordering
Best Practices
- WebSocket + registry + pub/sub routing
- Order per conversation; dedup for at-least-once
- Durable storage + offline delivery
Follow-up Questions
- How do you guarantee message ordering?
- How do you handle presence at scale?
- How do group messages fan out?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly β AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Message Queues (System Design) Interview question: "How would you design a real-time chat/messaging system?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair