Design a real-time messaging system

    A real-time chat system (WhatsApp/Messenger) must deliver messages instantly to online users, queue them for offline users, and scale to hundreds of millions of long-lived connections. The hard parts are connection management, routing a message to the right server, and delivery/read receipts.

    Real-Time & Messaging, 10 components, about 45 min

    The full guide covers requirements, estimates, the API, the data model, deep dives, trade-offs, failure modes and the follow-up questions interviewers ask.

    Read the full guide on Substack

    Key points

    • WebSocket gateway holds long-lived connections; sticky-routed by user_id hash.
    • Connection registry (Redis) maps user_id → gateway node for routing.
    • Messages persisted in Cassandra (wide rows by chat_id, sorted by time).
    • Offline users get APNs/FCM push via the notification worker.
    • Presence is best-effort — heartbeat in Redis with 30s TTL.

    Sign in to track this guide in your curriculum progress.