Design a real-time messaging platform supporting 50 million DAU, sub-100ms message delivery, online presence tracking, read receipts, and offline message queues.
Maintains long-lived WSS (WebSocket Secure) connection to Gateway.
Manages 10M active TCP/WebSocket connections, routes inbound/outbound push messages.
Maps user_id -> websocket_server_ip so incoming messages know which gateway node holds recipient connection.
Validates message payload, assigns snowflake sequence ID, pushes to DB and Notification queues.
Columnar database for high-throughput write speed and fast sequential time-range reads.
Dispatches APNs / FCM push notifications when recipient client is offline.
User A transmits message via active WebSocket connection.
Generate time-sortable Snowflake ID (e.g. 1728394028341).
Persist message to storage asynchronously.
Find which WebSocket Gateway holds User B connection.
Push message directly down WS Gateway 2 to User B device.
Send mobile alert badge if WebSocket is disconnected.