Each phone keeps one persistent WebSocket connection to a chat server. A session registry records which server each user is connected to, so a message can be stored, routed to the recipient's server over an internal bus and pushed down their socket in milliseconds. If the recipient is offline the message waits in the store and a push notification wakes their phone.
Functional requirements
- One-to-one and group chats with instant delivery
- Persistent history, synced across a user's devices
- Sent, delivered and read receipts; typing indicators; online/last-seen presence
- Send photos, video, voice notes and documents
- Push notifications when the app is closed
Non-functional requirements
- Sub-second delivery between online users
- No message is lost once the sender sees a single tick
- Messages appear in the same order for everyone in a conversation
- Millions of concurrent connections and billions of messages per day
- End-to-end encryption: servers relay ciphertext only
Extensions
- End-to-end encryption with per-device keys (Signal protocol).
- Voice and video calls using WebRTC with TURN relays.
- Message search on the device (since servers can't read content).
- Disappearing messages with TTL on storage.