How would you design a chat system?
Practice this questionShort explanation:
A chat service delivers messages to connected users while preserving enough state for offline users and reconnects. Persistent storage provides history, and WebSockets provide timely delivery to active connections. Message IDs, ordering rules and acknowledgements let clients recover without displaying duplicates or losing unseen messages.
Key points:
-
Use authenticated WebSocket connections for online updates.
-
Store messages durably with IDs and per-conversation ordering.
-
Track delivery/read state separately and support reconnects with missed-message fetching.
-
Persist a message before claiming durable acceptance and track read receipts separately from transport delivery.
-
Partition work by conversation where appropriate; a global message order is usually unnecessary and expensive.
Interview point:
- Explain how a reconnecting client resumes from its last known message and checks access to the conversation.