HardExperience level: 8-15 years1 min read

How would you design a real-time chat/messaging system?

Reviewed by Gurusankar M.

Asked inAmazonGoogleMicrosoft
#chat#websocket#message delivery#presence#fanout
Report issue

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

  1. How do you guarantee message ordering?
  2. How do you handle presence at scale?
  3. 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

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.