Realtime Messaging App Flow
A realtime messaging app flow describes how two mobile clients exchange messages with low latency through a persistent server-side connection, including connection establishment, message delivery, delivery receipts, and reconnection after network interruptions.
A realtime messaging app flow describes how two mobile clients exchange messages with low latency through a persistent server-side connection, including connection establishment, message delivery, delivery receipts, and reconnection after network interruptions.
Unlike a traditional request-response API where the client must poll for new messages, a realtime chat system uses a persistent bidirectional connection — typically a WebSocket — that remains open for the duration of the user's session. This allows the server to push new messages to the client the instant they arrive, enabling the sub-second delivery latency users expect from chat applications.
When the app foregrounds, it authenticates with the messaging server by sending a handshake frame containing the user's access token. The server validates the token, associates the connection with the user ID, and confirms the connection is ready. The client then subscribes to the channels or conversation IDs it wants to receive events for.
When a user sends a message, the client emits a message:send event over the WebSocket with a locally generated client_id (a UUID the client creates to deduplicate retries). The server persists the message to the database, broadcasts it to all connected recipients for that conversation, and acknowledges the sender with the server-assigned message ID and timestamp. Recipients' clients display the incoming message and send a message:delivered receipt, which is forwarded back to the sender's client to show the double-check delivery indicator.
Mobile network interruptions are common: when the WebSocket connection drops, the client detects the closure via a timeout on a periodic ping frame or a close event. It then reconnects with exponential backoff and requests messages received since its last known timestamp to fill the gap.
For delivering notifications when the app is backgrounded, see Push Notification Flow. For authentication setup, see Mobile App Authentication.