Design a Real-Time Chat System (WhatsApp)

Stateful WebSocket gateways, User-to-Server Redis registry, Snowflake IDs, delivery receipts, and offline push

Difficulty: Intermediate · Read time: 10 min · Access: Step-1 Preview + Knoera Pro

How It Works

Unlike stateless REST (Representational State Transfer) apps, real-time chat requires persistent bidirectional WebSocket (`wss://` — WebSocket Secure) TCP connections. Stateful WebSocket Gateways hold hundreds of thousands of open sockets each, while a Chat Service uses a Redis session registry (`user_id -> gateway_node`) and internal gRPC (Google Remote Procedure Call) to route messages across nodes. Messages are assigned time-sortable 64-bit Snowflake IDs, persisted in a wide-column database (Apache Cassandra / ScyllaDB) keyed by `(chat_id, msg_id)`, and queued for offline delivery via APNs (Apple Push Notification service) or FCM (Firebase Cloud Messaging).

Why It Matters

Chat systems combine stateful edge networking, per-conversation causal ordering, multi-stage delivery acknowledgments (`Sent ✓`, `Delivered ✓✓`, `Read`), and presence management without triggering reconnect or heartbeat storms.

Interactive Architecture Scenarios

  • 1-to-1 Message Delivery Across WS Gateways
  • Failure Mode: Gateway Crash & Presence Storm

Related Lessons in Real-World Case Studies