Design a Chat Application

HardReal-timeWebSocketsMessage QueuesReal-time SystemsDatabase DesignAbout 45 minutes

Design a real-time messaging system like Slack or WhatsApp. Users should be able to send messages in 1-on-1 and group conversations, see online presence, and receive messages in under 100ms. Design for 50M daily active users.

How the interview goes

Five phases, and questions the interviewer is likely to ask in each.

  1. 1. Requirements

    • What's the max group size?
    • Do messages need to be end-to-end encrypted?
    • How long should message history be retained?
    Show a hint

    Think about what 'real-time' means — WebSockets vs long polling vs SSE.

  2. 2. High-level design

    • How does a message find the right WebSocket server if users are on different instances?
    • How do you handle group chat fan-out at scale?
    • What's the database choice for storing messages?
    Show a hint

    A connection registry (e.g., Redis pub/sub) is needed to route messages to the right WebSocket server.

  3. 3. Deep dive

    • How do you guarantee message ordering in a distributed system?
    • How does your presence system avoid stale online status?
    • How do you handle messages sent while a user is offline?
    Show a hint

    Cassandra's wide-column model works well for time-ordered message storage.

  4. 4. Scaling

    • How do you scale WebSocket connections across many servers?
    • What's your sharding strategy for the message database?
    • How do you handle a group with 100K members?
    Show a hint

    Fan-out for large groups often uses a message queue to avoid blocking the sender.

  5. 5. Trade-offs

    • What's the trade-off between at-least-once and exactly-once delivery?
    • Pull vs push for message delivery — when would you choose each?
    Show a hint

    At-least-once delivery requires client-side deduplication; exactly-once is very expensive.

Practice this with an AI interviewer

Write your design doc with live diagrams while the interviewer asks one question at a time and pushes on your choices. Get a scored debrief with what to study next.

Start this interview