Interview Questions/System Design/Design a Real-Time Chat System
AdvancedSystem-Design
45 min

Design a Real-Time Chat System

RealtimeMessagingStorageNetworking
Advertisement
Interview Question

Design a web/mobile chat system with 1:1 and group chats, typing indicators, presence, read receipts, and offline support.

Key Points to Cover
  • Transport: WebSockets/HTTP2, fan-out, connection gateways
  • Data model: conversations, messages, membership, ACLs
  • Ordering/delivery: IDs, vector clocks/lamport, exactly-once effects via idempotency
  • Scaling: sharding by user/conversation, partitions, backpressure
  • Mobile/offline: sync, conflict resolution, compaction
  • Moderation/security: E2EE vs server-side features trade-offs
Evaluation Rubric
Real-time transport and fan-out plan25% weight
Sound schema and delivery semantics25% weight
Sharding, load, and backpressure25% weight
Offline, presence, and receipts25% weight
Hints
  • 💡Consider gateway layer (e.g., Envoy) for millions of sockets.
Common Pitfalls to Avoid
  • ⚠️Underestimating the complexity of message ordering and 'exactly-once' delivery guarantees in a distributed system, leading to duplicate or out-of-order messages.
  • ⚠️Ignoring the implications of offline users, resulting in lost messages or poor synchronization upon reconnection.
  • ⚠️Choosing an inappropriate primary data store (e.g., a single relational database) that cannot handle the read/write throughput and storage requirements for chat messages and presence.
  • ⚠️Lack of a clear strategy for managing and scaling real-time connections (WebSockets) and connection state across multiple servers.
  • ⚠️Failing to implement robust ACLs and permission checks for group chats, potentially exposing sensitive information or allowing unauthorized actions.
Potential Follow-up Questions
  • How would you support E2EE?
  • How do you handle message edits/deletes?
Advertisement