7 min read

Design WhatsApp: System Design Interview Walkthrough

By the BuildTheSystem team

Design WhatsApp: System Design Interview Walkthrough

Designing a real-time messaging platform like WhatsApp is one of the most common system design interview questions. Interviewers favor this problem because it tests stateful connection management, data persistence under heavy write loads, and low-latency message delivery.

To clear this interview round, you need a structured strategy that fits into a standard 45-minute format. This walkthrough breaks down how to pace your answer, from requirements gathering to detailed architecture decisions. If you want to build confidence before your real interview, practicing with AI mock interviews for system design provides real-time feedback on your architecture and communication.

Clarifying Requirements and Scoping the System

Begin by spending the first 3 to 5 minutes defining scope. Chat applications have vast feature sets, so establishing clear boundaries prevents you from running out of time.

Functional Requirements

  • One-on-one instant messaging between active users.
  • Small group chats with up to 100 participants.
  • Message delivery receipts, including sent, delivered, and read status.
  • Support for offline message delivery when users reconnect.

Non-Functional Requirements

  • Ultra-low delivery latency under 200 milliseconds for online users.
  • High availability for the messaging transport tier.
  • Strong consistency for message order within an individual chat session.
  • Durable storage ensuring zero message loss once acknowledged by servers.

Out of scope for this 45-minute breakdown are voice and video calls, end-to-end encryption key management, and large broadcast channels.

Back-of-the-Envelope Capacity Estimates

Spend about 5 minutes quantifying the scale. Presenting explicit numerical assumptions shows the interviewer you design around realistic constraints.

Assume 500 million daily active users (DAU). Assume each active user sends an average of 40 messages per day.

Message Throughput

  • Total daily messages: 500 million times 40, which equals 20 billion messages per day.
  • Average writes per second: 20 billion divided by 86,400 seconds, resulting in roughly 230,000 messages per second.
  • Peak writes per second: Assuming a 2x peak traffic multiplier, design for 460,000 messages per second.

Storage Requirements

  • Assume an average message size of 200 bytes, which includes text content, sender ID, receiver ID, and timestamp.
  • Daily storage: 20 billion messages times 200 bytes equals 4 terabytes per day.
  • Five-year storage requirement: 4 terabytes times 365 days times 5 years, totaling approximately 7.3 petabytes of message data.

Connection Scale

  • Assume 50 percent of daily active users remain connected simultaneously during peak hours.
  • Simultaneous active connections: 250 million persistent connections running concurrently.

High-Level Architecture and Flow

Spend 10 minutes establishing the overall architecture diagram.

The system splits into stateless services for API operations and stateful connection managers for live messaging. HTTP REST endpoints handle account creation, login, and asset uploads. A pool of WebSocket connection servers holds persistent TCP streams to client devices.

When User A sends a message to User B, the workflow proceeds as follows:

  1. User A pushes a JSON message payload over an active WebSocket connection to a WebSocket server node.
  2. The WebSocket server forwards the payload to an internal Message Ingestion Service.
  3. The Message Ingestion Service writes the message to a persistent message database and publishes an event to a Kafka event stream.
  4. A Delivery Service consumes the event and queries a Connection Registry to find which WebSocket server holds User B's connection.
  5. If User B is online, the target WebSocket server pushes the payload over User B's socket.
  6. If User B is offline, the Delivery Service routes the payload to a Push Notification Service.

Before moving to individual components, ensure your API endpoints are protected against abuse. Applying patterns from Design a Rate Limiter: A System Design Interview Walkthrough helps shield authentication and contact synchronization services from sudden traffic spikes. You can also explore candidate architecture blueprints using the free system design playground.

Managing Real-Time WebSocket Connections

Dedicate 8 minutes to explaining connection maintenance, as stateful servers present distinct scaling challenges.

Standard HTTP requests are client-initiated, making them ill-suited for server-pushed updates. Long polling holds HTTP requests open until data arrives, but establishing new requests repeatedly introduces unnecessary overhead. WebSockets establish a full-duplex TCP channel after an initial HTTP handshake, allowing instantaneous two-way messaging over a single connection.

Connection Registry and Session Tracking

Because connections are stateful, any server in the cluster must quickly locate which node hosts a target user.

Maintain a Connection Registry using a distributed in-memory cache like Redis. When a user connects to a WebSocket server, that server writes a mapping of user_id -> websocket_server_ip with a TTL of 60 seconds. The client sends a heartbeat every 30 seconds to refresh this key. If a WebSocket server crashes, the heartbeats expire, clearing stale connection states automatically.

Scaling 250 Million Connections

A single Linux server can support around 100,000 concurrent open sockets if file descriptor limits and kernel memory parameters are tuned. To host 250 million simultaneous connections, deploy a fleet of roughly 2,500 WebSocket nodes behind layer-4 load balancers.

Message Storage and Database Schema

Spend 8 minutes detailing how data is stored and retrieved.

Message storage requires high write throughput, low latency range scans for chat history, and horizontal scalability. Traditional relational databases encounter lock contention and indexing overhead under 460,000 peak writes per second. A wide-column NoSQL store like Apache Cassandra fits these access patterns.

Cassandra Schema Design

In Cassandra, data model design depends directly on query patterns. The primary queries are loading recent messages for a conversation and appending new messages.

CREATE TABLE messages (
    channel_id uuid,
    message_id timeuuid,
    sender_id uuid,
    content text,
    created_at timestamp,
    PRIMARY KEY (channel_id, message_id)
) WITH CLUSTERING ORDER BY (message_id DESC);

Ordering and Identification

channel_id serves as the partition key, placing all messages within a specific conversation on the same physical database node cluster. message_id uses a TimeUUID, which combines a timestamp with a node identifier to ensure chronological ordering and prevent primary key collisions.

For 1-on-1 chats, channel_id is a deterministic hash of the two participant IDs. For group chats, channel_id maps to a unique group identifier.

Handling Offline Users and Push Notifications

Spend 5 minutes describing offline state handling and push delivery.

When a message arrives for User B, the Delivery Service checks the Redis Connection Registry. If no active entry exists, User B is marked offline.

Offline Message Queue

Instead of attempting socket delivery, the system stores the unread message in Cassandra and enqueues a push payload into a Kafka topic reserved for notification processing.

Push Notification Pipeline

A dedicated worker pool consumes from the push notification queue and invokes third-party gateway services such as Apple Push Notification service (APNs) or Firebase Cloud Messaging (FCM). The push payload contains minimal metadata, prompting the client application to wake up and fetch full unread message threads upon reconnecting.

When the client establishes a new WebSocket connection, it sends its last received message_id. The Chat Service queries Cassandra for all messages where channel_id = X and message_id > last_received_id, streaming missing messages down to the client.

Key System Trade-offs and Bottlenecks

Dedicate 4 minutes to reviewing architectural trade-offs and potential system failures.

Trade-Off 1: Eventual Consistency vs Strong Consistency

Using Cassandra prioritizes write availability over strict ACID transactions. In rare network partitioning events, two nodes might accept messages out of strict chronological order. Using TimeUUIDs mitigates client display errors by reordering messages on the device based on server-side creation timestamps.

Trade-Off 2: In-Memory Connection State vs Centralized Lookup

Storing state in Redis introduces an extra network hop for every message delivery lookup. An alternative is maintaining local routing tables across nodes using a peer-to-peer gossip protocol. However, Redis provides easier scaling and predictable latency at the cost of running a centralized cache cluster.

Where the Architecture Breaks Down

  • Hot Partition Limits: Extremely popular group channels with tens of thousands of users can overwhelm a single Cassandra partition. Solved by capping group sizes or bucketing partition keys by date.
  • Cascading Reconnections: A sudden network failure causing millions of clients to reconnect simultaneously can crush the authentication service and WebSocket load balancers. Solved by implementing exponential backoff with jitter on client connection retries.

What to Say Out Loud During the Interview

Conclude your design by demonstrating effective communication techniques. Interviewers evaluate your ownership and structured thinking just as much as your technical choices.

How to Narrate Decisions

  • Proactively state assumptions: "I am assuming 500 million daily users sending 40 messages daily, which translates to a peak write volume of 460,000 operations per second."
  • Explain trade-offs before picking technologies: "We could use HTTP long polling, but persistent WebSockets eliminate continuous request headers and lower server overhead for high-frequency messaging."
  • Acknowledge system limitations early: "While Cassandra gives us linear write scale, we must structure partition keys carefully so single high-volume group chats do not create hot spots."

By framing your answer around clear requirements, explicit estimates, layered architectural components, and honest trade-offs, you demonstrate senior-level system design maturity.

Frequently asked

Why use WebSockets instead of HTTP long polling for WhatsApp?

WebSockets provide low-latency, full-duplex communication over a single TCP connection after an initial HTTP upgrade handshake. Long polling incurs higher connection setup overhead and unnecessary header transfers under frequent bidirectional messaging.

Why is Cassandra preferred over PostgreSQL for chat message storage?

Cassandra provides high write throughput and horizontal scaling without requiring complex database sharding schemes. Its partition-key structure naturally aligns with fetching conversation histories ordered by timestamps.

How does WhatsApp maintain message ordering across client devices?

Messages are assigned monotonically increasing IDs or TimeUUIDs generated by the server. When client devices fetch or receive messages out of order, they sort them locally using these identifiers before displaying them in the conversation view.

Rehearse this out loud, not just on paper

BuildTheSystem runs a live mock interview on a typed-component whiteboard — the interviewer listens, waits while you draw, and reacts the moment you connect something questionable.

Start a mock interview