InterviewHubPRO
Section Overview
Q13

Question 13 of 50

Part 2: Real-World High-Scale Architecture Problems (11 - 25)

26%
System Design (50 Qs)•Part 2: Real-World High-Scale Architecture Problems (11 - 25)

Design a Real-Time Chat System (WhatsApp / Slack / Discord).

In Simple Words: Support 1-on-1 private messaging, group channels, persistent chat history, and online status with end-to-end delivery guarantees.

Core Components:

  • Connection Handshake: Client connects via HTTP/HTTPS, authenticates, and upgrades connection to bidirectional WebSocket.
  • Chat Service Cluster: Maintains active persistent TCP/WebSocket connections.
  • Redis Presence & Session Registry: Maps userId → server_id to know which server holds a user's active socket connection.
  • Message Broker (Kafka / Redis Pub/Sub): Routes messages across different chat servers when User A and User B are connected to different physical nodes.
Architecture Flowchart
sequenceDiagram
    autonumber
    actor Alice
    participant CS1 as Chat Server 1
    participant Redis as Redis Registry (Session Map)
    participant Queue as Kafka / PubSub
    participant CS2 as Chat Server 2
    actor Bob

    Alice->>CS1: Send Message: { to: "Bob", text: "Hello" }
    CS1->>Redis: Lookup Bob's active server
    Redis-->>CS1: Bob is on Chat Server 2
    CS1->>Queue: Publish event to "server-2" channel
    Queue->>CS2: Deliver message
    CS2->>Bob: Push over WebSocket connection
    Bob-->>CS2: ACK (Delivered)
    CS2->>CS1: Forward ACK
    CS1-->>Alice: Double checkmark (Delivered)