Chat System Interview Questions
How would you design WhatsApp / a chat system? — spoken sample answer for Indian interviews.
- 5Questions with answers
- 3Difficulty levels
Questions (5)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
How would you design WhatsApp / a chat system?
I would ask 1:1 vs groups, receipts, media, multi-device, and encryption up front. Mobile clients keep a long-lived connection to a gateway. The gateway maps userId to connection. When I send a message, it hits a chat service, gets persisted keyed by conversation and timestamp, then the gateway pushes to the other person. If they are offline, we store and forward. Small groups can fan-out on write. Huge groups should fan-out on read or I will melt the writer. Media does not live in the chat DB — object storage plus CDN, chat only stores the URL. Presence is Redis with TTLs. If they want WhatsApp-style E2E encryption, the server stores ciphertext and cannot read messages. I would also mention idempotent message ids so retries do not double-send, and unread counters as a separate small service.
How do you deliver messages if a user is offline?
I persist the message first, then try push. If the device is offline I keep it in the inbox store keyed by user and sync on connect. I would not only use in-memory pub/sub. Fan-out on write for small group chats, fan-out on read for huge groups or channels. Acknowledgements give at-least-once delivery; clients dedupe by message id. I mention push notifications as a separate channel, not as the source of truth.
1:1 chat versus group chat of 10,000 members — what changes?
1:1 I can fan-out on write to two inboxes. A 10,000 member group I should not write 10,000 copies on every message if activity is high. I store the message once in a group log and let clients pull new offsets, or I fan-out only to online members and let others catch up. Presence and typing indicators must be ephemeral and sampled. I would not reuse the 1:1 table design blindly for huge rooms.
How do you order messages and handle clocks that are wrong?
I would not trust client clocks. The server assigns a monotonic sequence per conversation, or I use a hybrid logical clock. Clients can show optimistic UI, then reconcile. If two messages race, the conversation id plus sequence breaks ties. I mention that 'last write wins' on an edited message needs an edit version. WhatsApp-style ticks are client UX on top of server order, not a substitute for it.
Where do you store media, and how do you keep the message path fast?
Images and video go to object storage. The chat message stores a URL and metadata, not the blob. Upload is a separate API, often with a pre-signed URL. The websocket path stays small. I would CDN the media. I would not send 20 MB through the same channel as 'typing...'. Virus scan and size limits belong on the upload path.
Practice with AI mock interviews
Run System Design mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required