HardπŸ‘€ 8-15 years 1 min read

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

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.

β˜•Coffee Chat Question

Concept Made Simple

β€œHow would you design a real-time chat/messaging system?”

🧠Mind Map Answer

Remember It Faster

Transport→WebSocket + connection registry
Persist→ordered messages per conversation
Route→pub/sub to recipient's gateway
Also→offline delivery, presence, receipts

πŸ”₯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:

βœ“ 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

  • 1How do you guarantee message ordering?
  • 2How do you handle presence at scale?
  • 3How do group messages fan out?

🧩Related Technologies

WebSocketRedis pub/subKafkapresence service

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?

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.

Related Questions