How would you design a real-time chat/messaging system?
β‘ 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.
βCoffee Chat Question
Concept Made Simple
βHow would you design a real-time chat/messaging system?β
π§ Mind Map Answer
Remember It Faster
π₯What If?
Think Beyond the Expected
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:
β οΈ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
- 1How do you guarantee message ordering?
- 2How do you handle presence at scale?
- 3How do group messages fan out?
π§©Related Technologies
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?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.